private bool TryAttack(GeneticGridDirection direction) { GridPosition myPosition = GameObjectGrid.WorldToGridPosition(this.transform.position); GridPosition victimPosition = myPosition.GetPositionInDirection(direction.Value); if (!GameObjectGrid.PositionIsAlive(victimPosition)) { return(false); } GameObject victim = GameObjectGrid.GetObjectAt(victimPosition); EntBehaviorManager victimManager = victim.GetComponent <EntBehaviorManager>(); int damage = (this.AttackStrength.Value * this.Health.Value) / InitialHealth; victimManager.TakeDamage(damage); // Will succeed if we killed the victim if (this.TryMove(direction)) { this.TryAddHealth(victimManager.GrowFoodStrength.Value); } if (this.AttackStrength.Value < StaticController.GlobalMaxInt) { ++this.AttackStrength.Value; } if (this.GrowFoodStrength.Value > 1) { --this.GrowFoodStrength.Value; } return(true); }
private byte DirectionIsFriend(byte direction) { GridPosition currentPosition = GameObjectGrid.WorldToGridPosition(this.transform.position); GridPosition testPosition = currentPosition.GetPositionInDirection(direction); if (!GameObjectGrid.PositionIsAlive(testPosition)) { return(0); } GameObject neighbor = GameObjectGrid.GetObjectAt(testPosition); EntBehaviorManager manager = neighbor.GetComponent <EntBehaviorManager> (); if (CommonHelperMethods.StringsAreEqual(manager.TeamName, this.TeamName)) { return(1); } return(0); }
private GeneticBool DirectionIsEnemy(GeneticGridDirection direction) { GridPosition currentPosition = GameObjectGrid.WorldToGridPosition(this.transform.position); GridPosition testPosition = currentPosition.GetPositionInDirection(direction.Value); if (!GameObjectGrid.PositionIsAlive(testPosition)) { return(GeneticBool.False); } GameObject neighbor = GameObjectGrid.GetObjectAt(testPosition); EntBehaviorManager manager = neighbor.GetComponent <EntBehaviorManager> (); if (CommonHelperMethods.StringsAreEqual(manager.TeamName, this.TeamName)) { return(GeneticBool.False); } return(GeneticBool.True); }
private byte TryAttack(byte direction) { GridPosition myPosition = GameObjectGrid.WorldToGridPosition(this.transform.position); GridPosition victimPosition = myPosition.GetPositionInDirection(direction); if (!GameObjectGrid.PositionIsAlive(victimPosition)) { return(0); } GameObject victim = GameObjectGrid.GetObjectAt(victimPosition); EntBehaviorManager victimManager = victim.GetComponent <EntBehaviorManager>(); int damage = (this.AttackStrength * this.Health) / InitialHealth; if (damage > byte.MaxValue) { damage = byte.MaxValue; } victimManager.TakeDamage((byte)damage); // Will succeed if we killed the victim if (this.TryMove(direction) == 1) { this.TryAddHealth(victimManager.GrowFoodStrength); } if (this.AttackStrength < byte.MaxValue) { ++this.AttackStrength; } if (this.GrowFoodStrength > byte.MinValue) { --this.GrowFoodStrength; } return(1); }