Ranger forgot how to use his gun

When playing in the forest level “Tactical Timing”, my ranger is unable to use his gun. I have tried switching out my bought weapon with the freebie crossbow he came with, but no change. I also added the attack range thinking that could be the problem. I have him say a message to see if he’s firing and my eyes have just missed it, but he never says “bam!”.

Is this a game bug, or just something I’m missing in my code?

// Help out on the front line.
// Move back to a flag if any try to sneak by.
loop{
    var enemy = this.findNearest(this.findEnemies());    
    var flag = this.findFlag();
    if(flag){
        this.pickUpFlag(flag);
    }
    if(enemy){
        if(this.isReady("throw") && this.distanceTo(enemy) < this.throwRange){
            this.throw(enemy);
        }else if(this.canCast("chain-lightning", enemy)){
            this.cast("chain-lightning", enemy);
        }else if(this.canElectrocute(enemy)){
            this.electrocute(enemy);
        }else if(this.distanceTo(enemy) < this.attackRange){
            this.attack(enemy);
            this.say("bam!");
        }else{
            this.heal(this);
        }
    }
}

Heal has a cooldown. You’re telling yourself to heal when there’s no attackers in range. However, if you use heal before it is ready, then your hero is stuck trying to cast heal until it is ready. Add a if (this.canCast("heal")) {.

Hmm, removing heal entirely didn’t make the problem go away.

...
if(enemy){
        if(this.isReady("throw") && this.distanceTo(enemy) < this.throwRange){
            this.throw(enemy);
        }else if(this.canCast("chain-lightning", enemy)){
            this.cast("chain-lightning", enemy);
        }else if(this.canElectrocute(enemy)){
            this.electrocute(enemy);
        }else{
            this.attack(enemy);
            this.say("bam!");
        }
    }

To pass this level (in other words to kill all ogres before time ran out), I had to delete all of my special attacks.

loop{
    var enemy = this.findNearest(this.findEnemies());    
    var flag = this.findFlag();
    if(flag){
        this.pickUpFlag(flag);
    }
    if(enemy){
        this.attack(enemy);
    }
}

Which is kinda :cry: really.

Huh. I doubt this intentional. Well, when in doubt, call @nick.

this.electrocute() also has an isReady check, so you’ll also have to add that before you attempt to electrocute someone.

if (this.isReady('electrocute') && this.canElectrocute(enemy)) {
    this.electrocute(enemy)
} else {
    this.attack(enemy)
}
```
2 Likes

Ah that’s what it was. Who would’ve thought electrocuting somebody would be so complicated.

Thanks trotod and ChronistGilver for looking through my code!

Also, self.say() can burn a lot of time. Whenever you say, your character stops for a long moment.

Also, you might want to clean up your special attack tests.

  1. Electrocute only slows down the run speed of your target from the descriptions I have seen. So, if the target is already attacking you and you are not planning to run, why are you using it? Also, I think the canElectrocute already incorporates the cool down, but I could be wrong on that.
  2. Chain-lightning has a long cool down and can jump between targets up to 8 times, doing less damage each time. You may want to consider checking to make sure there is another enemy within 20 feet of your first target. In Python, I might suggest:
    TarB = enemy.findNearest(enemy.findEnemies())
    if TarB:
    …DistanceToTarB = enemy.DistanceTo(TarB)
    …if DistanceToTarB < 20:
    …self.cast(“chain-lightning”, enemy)

That way, there are at least 2 targets. Depending on level, you might want to check the .health of the first target is greater than 99 as well.

1 Like

canElectrocute should incorporate the cooldown, but I guess it doesn’t. Anyone up for submitting a patch?

Actually, I think canElectrocute actually does incorporate the cooldown currently or it is a really short cool down as I have not noticed a significant pause while waiting for it to fire. If it doesn’t, wish I knew enough to be able to develop and submit a patch…

If we were programming in Basic (the original mind you), Pascal, LISP or Visual Basic for Applications (many, many years ago), I might have the nerve to propose such a patch. To be honest, I originally came here looking for ways to teach my youngest how to code and got into solving the problems. If you’re looking for a true coder, I’m a far better attorney these days. :wink:

Some interesting strategies to try our Msakr. Thanks for the tips!

Did I understand correctly that the electrocute ring and the gloves share the same cool-down?

That is incorrect. The Steel Ring’s electrocute ability has a cooldown of eight seconds, while the Emperor’s Gloves’ chain-lightning has a cooldown of twenty seconds.

Just maybe use another hero like Tharin.