Scopo
Scopo

Reputation: 301

Only assignment, call, increment, decrement, await, and new object expressions

I posted a question about this code yesterday, but I did it... really badly. I've since talked with a friend of mine who knows coding very well and tried a few things, but I've genuinely hit a wall with this. I tried looking at other questions of the same accord, but none of their solutions worked for me...

What I am trying to do is overwrite "effectiveness". The server is taking the effectiveness as 4 or 5 (I am not sure which, but it's definitely one of the two-- It doesn't matter which, anyway). I want it to take it as 7 or above. I figured out how to call effectiveness data from the server, but it still doesn't seem to be working. 4/5 effectiveness gives me the text "It's not very effective...", which keeps happening when I try to use the code.

This is my code (There is a lot more to it, but I have removed what is irrelevant):

public partial class Main {
    public static int effectiveness;
    public static void BeforeMoveHits(BattleSetup setup) {
        try {
            if (setup.Defender != null) {
                switch (setup.Move.AdditionalEffectData3) {
                    case 69: { //Freeze Dry
                            if (setup.Defender.Type1 == Enums.PokemonType.Water ||
                                setup.Defender.Type2 == Enums.PokemonType.Water) {  
                                DamageCalculator.Effectiveness[256];
                            }
                        }
                        break;
                     }
                 }
         }
    }
}

As stated in the tile, when I try to compile it, I get the error

only assignment, call, increment, decrement, await, and new object expressions can be used as a statement.

The

public static int effectiveness

is left over from when I tried using "effectiveness = 8" as opposed to DamageCalculator.Effectiveness. Removing it affects nothing, so I've left it there in case I need it later.

In DamageCalculator.cs, this is what sets effectiveness:

public static int[] Effectiveness = new int[9] {2, 8, 16, 64, 96, 160, 256, 416, 640};

You can view the full code here if you find it helpful.

There's also a tidbit of info about effectiveness in BattleProcessor.cs, though I doubt its relevancy as I continue to work on this...

    public static string EffectivenessToPhrase(int effectiveness) {
        if (effectiveness < 4) {
            return "It has little effect...";
        } else if (effectiveness < 6) {
            return "It's not very effective...";
        } else if (effectiveness == 7) {
            return "It's super-effective!";

        } else if (effectiveness > 7) {
            return "It's super-effective!!!";
        } else {
            return null;
        }
    }

This is the full code of BattleProcessor.cs, if you need it.

It's worth noting that I cannot change BeforeMoveHits from void, and I cannot change Main to anything besides partial. Doing so will break other parts of the game this is for. That being said, if changing effectiveness isn't possible because of these circumstances, just tell me. I'll... try to figure out something else to do what I want.

Upvotes: 0

Views: 2410

Answers (3)

user3598756
user3598756

Reputation: 29421

If the code you linked for BattleProcessor class is actually mostly commented as I see it, then you can

  • exploit its EffectivenessToPhrase() method passing it a sufficiently high effectiveness parameter

    string effectivenessToPhrase =  BattleProcessor.EffectivenessToPhrase(7);
    

    this would only affect the ToPrhase output

  • change Effectiveness[] values so as to mimic higher indexes:

    DamageCalculator.Effectiveness[4]=256;
    DamageCalculator.Effectiveness[5]=256;
    

    this would affect whatever code will be using DamageCalculator.Effectiveness

    then you must get those values back to original ones (respectively, 96 and 160) as soon as your task is accomplished

Upvotes: 0

Hakan Fıstık
Hakan Fıstık

Reputation: 19421

There is no meaning to statement

DamageCalculator.Effectiveness[256];

this statement is returning a value which you are not using at all. you need at a least to save the value which you return in some variable to use it later. Or why you really doing this.

the following statement will solve the compile time error.

var temp = DamageCalculator.Effectiveness[256];

BTW the

DamageCalculator.Effectiveness[256];

will thrown an exception after you make the code could be compiled. The exception will be IndexOutOfRangeException and at that time solve this problem by the following statement

DamageCalculator.Effectiveness[6]

Upvotes: 1

Frank Stefan
Frank Stefan

Reputation: 50

Your statement "Damagecalculator.effectiveness[256]" makes no sense. You don't define or assign anything here. I think that's why the compiler complains. You're using the array wrong. Just use a simple integer to set the effectiveness. If you want the effectiveness to be set at this specific numbers, you should use enumerators.

Upvotes: 1

Related Questions