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 bool TryMove(GeneticGridDirection direction) { return(GameObjectGrid.TryMoveObject( this.TeamName, TeamManager.GetTeamColor(this.TeamName), GameObjectGrid.WorldToGridPosition(this.transform.position), direction.Value)); }
private bool TryReproduce(GeneticGridDirection direction) { GridPosition myPosition = GameObjectGrid.WorldToGridPosition(this.transform.position); GridPosition childPosition = myPosition.GetPositionInDirection(direction.Value); return(GameObjectGrid.TryReviveObjectAt( this.TeamName, TeamManager.GetTeamColor(this.TeamName), childPosition, false)); }
private GeneticBool DirectionIsOccupied(GeneticGridDirection direction) { GridPosition currentPosition = GameObjectGrid.WorldToGridPosition(this.transform.position); GridPosition testPosition = currentPosition.GetPositionInDirection(direction.Value); if (GameObjectGrid.PositionIsAlive(testPosition)) { return(GeneticBool.True); } return(GeneticBool.False); }
/// <summary> /// Writes to variable. /// </summary> /// <param name="signature">Signature.</param> /// <param name="value">Value.</param> public void WriteToVariable(VariableSignature signature, GeneticObject value) { if (signature.VariableId == EntVariableEnum.HelperInt1) { this.HelperInt1 = value as GeneticInt; return; } if (signature.VariableId == EntVariableEnum.HelperInt2) { this.HelperInt2 = value as GeneticInt; return; } if (signature.VariableId == EntVariableEnum.HelperBool1) { this.HelperBool1 = value as GeneticBool; return; } if (signature.VariableId == EntVariableEnum.HelperBool2) { this.HelperBool2 = value as GeneticBool; return; } if (signature.VariableId == EntVariableEnum.HelperGridDirection1) { this.HelperGridDirection1 = value as GeneticGridDirection; return; } if (signature.VariableId == EntVariableEnum.HelperGridDirection2) { this.HelperGridDirection2 = value as GeneticGridDirection; return; } LogUtility.LogErrorFormat( "No implementation found for writable variable: {0}", signature); }
private GeneticBool DirectionIsFriend(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.True); } return(GeneticBool.False); }