// Deals a weak shock to the unit public static bool weakShock(ref Unit unit, int x, int y, Trap trap, ref BattleMap map, ref Unit parent) { if(unit== null) return false; unit.health-= 8; Console.WriteLine("Dealt 8 damage, Unit's hp: "+unit.health); return true; }
// --- Constructors --- public Tile(GameExt pmGame, Vector3 pmPos, ref BattleMap pmMap) : base(pmGame, pmGame.models.get("tile"), pmPos) { texture= game.textures.get(getTextureName()); unitID= new int[] {-1, -1}; startZoneID= -1; map= pmMap; pos-= new Vector3(-Tile.size/2f, 0f, Tile.size/2f); bounds= new float[] { pmPos.X, pmPos.X+Tile.size, pmPos.Z-Tile.size, pmPos.Z }; trap= null; color= getNormalColor(); }
// Called when the unit is being to set down a trap public virtual Trap onSetTrap(Profession pref, ref Unit unit, int x, int y, ref Trap trap, ref BattleMap map) { return trap; }
// Called when the unit has set's off the trap public virtual bool onSetOffTrap(Profession prof, ref Unit unit, ref Unit parent, int x, int y, bool canSetOff, ref Trap trap, ref BattleMap map) { return canSetOff; }
// Finds if setting of traps cannot set down the trap private bool trap_canStopSet(ref int x, ref int y, ref int radius, ref int maxRadius, ref Trap trap) { if(trap== null) return true; if(x< 0 || x>= tiles.width) return true; if(y< 0 || y>= tiles.height) return true; if(radius> maxRadius) return true; if(tiles.items[x, y].item== null) return true; if(tiles.items[x, y].item.trap!= null) return true; if(tiles.items[x, y].path< radius && tiles.items[x, y].path!= -1) return true; return false; }
// Does a dijkstra algorithm to set down a trap. Use attack search to get where to set down your trap private void p_setTrap(int x, int y, int radius, ref int maxRadius, ref Trap trap, ref int teamID, ref int unitID) { if(trap_canStopSet(ref x, ref y, ref radius, ref maxRadius, ref trap)) return; tiles.items[x, y].path= radius; if(teamID!= -1 && unitID!= -1) tiles.items[x, y].item.trap= (teams.items[teamID].units.items[unitID].onSetTrap(x, y, ref trap, this)).clone(); else tiles.items[x, y].item.trap= trap.clone(); p_setTrap(x, y+1, radius+1, ref maxRadius, ref trap, ref teamID, ref unitID); p_setTrap(x+1, y, radius+1, ref maxRadius, ref trap, ref teamID, ref unitID); p_setTrap(x, y-1, radius+1, ref maxRadius, ref trap, ref teamID, ref unitID); p_setTrap(x-1, y, radius+1, ref maxRadius, ref trap, ref teamID, ref unitID); }
public void setTrap(int[] unitID, int x, int y, int radius, Trap trap) { p_setTrap(x, y, 0, ref radius, ref trap, ref unitID[0], ref unitID[1]); }
public void setTrap(int teamID, int unitID, int x, int y, int radius, Trap trap) { p_setTrap(x, y, 0, ref radius, ref trap, ref teamID, ref unitID); }
// Called when the unit is about to set down a trap public virtual Trap onSetTrap(int x, int y, ref Trap trap, BattleMap map) { return prof.onSetTrap(this, x, y, ref trap, ref map); }
// Called when the unit has set's off the trap public virtual bool onSetOffTrap(ref Unit parent, int x, int y, ref Trap trap, ref BattleMap map) { return prof.onSetOffTrap(this, ref parent, x, y, ref trap, ref map); }
// Clones the trap with a given new team id public Trap clone(int newTeamID) { // Variables Trap trap= new Trap(trapEvent, newTeamID, name, ref parent); Trap.ntid--; trap.trapID= trapID; return trap; }
// Called when the unit is about to set down a trap public virtual Trap onSetTrap(Unit unit, int x, int y, ref Trap trap, ref BattleMap map) { // Variables Passive passive; for(int i= 0; i< currPassives.Length; i++) { if(currPassives[i]== null) continue; if(passives.get(currPassives[i], out passive)) trap= passive.onSetTrap(this, ref unit, x, y, ref trap, ref map); } return trap; }
// Called when the unit has set's off the trap public virtual bool onSetOffTrap(Unit unit, ref Unit parent, int x, int y, ref Trap trap, ref BattleMap map) { // Variables Passive passive; bool canSetOff= true; for(int i= 0; i< currPassives.Length; i++) { if(currPassives[i]== null) continue; if(passives.get(currPassives[i], out passive)) canSetOff= passive.onSetOffTrap(this, ref unit, ref parent, x, y, canSetOff, ref trap, ref map); } return canSetOff; }