public void Straight() { ep.Add(-20); if (ep.IsZero) { return; } Point3D targetPosition = this.position.Copy(); SkillManager.showSkill(Skill.straight, this); for (int i = 0; i < 3; ++i) { targetPosition.MoveFor(this.vector, 1); Grid targetGrid = World.GetAt(targetPosition); if (targetGrid == null) { return; } if (targetGrid.Obj == null) { continue; } if (targetGrid.Obj is Attackable) { Attackable target = (Attackable)targetGrid.Obj; target.BeAttack(this); } } }
public void Attack() { // 攻擊不耗魔. Point3D targetPosition = this.position.Copy(); SkillManager.showSkill(Skill.attack, this); targetPosition.MoveFor(this.vector, 1); Grid targetGrid = World.GetAt(targetPosition); if (targetGrid == null) { return; } if (targetGrid.Obj == null) { return; } if (targetGrid.Obj is Attackable) { Attackable enemy = (Attackable)(targetGrid.Obj); enemy.BeAttack(this); } }
private void Move() { Point3D temp = this.position.Copy(); temp.MoveFor(vector, 1); Grid targetGrid = World.GetAt(temp); if (targetGrid == null) { return; } if (targetGrid.Obj != null) { if (targetGrid.Obj is Food) { EatFood((Food)targetGrid.Obj); } else { return; } } World.Swap(position, temp); RegisterEvent(ObjEvent.posit); // 當照著路線走時,會把走過的標記移除. if (route != null && route.Count > 0) { if (route.Peek() == this.Vect) // 照著路線走. { route.Pop(); } else // 偏離路線,原本的路線已經沒用了. { route = null; } } }
public void Build() { ep.Add(-10); if (ep.IsZero) { return; } Point3D targetPosition = this.position.Copy(); targetPosition.MoveFor(this.vector, 1); Grid targetGrid = World.GetAt(targetPosition); if (targetGrid == null) { return; } if (targetGrid.IsEmpty()) { targetGrid.InsertObj(new Wall(targetPosition, Power * 5)); } }
// 招集附近的流浪夥伴一起蓋新家. private void FindNewHome() { if (this.Hometown != null) { return; } Point3D position = this.position.Copy(); position.MoveFor(this.vector, 1); Grid targetGrid = World.GetAt(position); if (targetGrid == null || targetGrid.Obj != null) { return; } Point2D positOnPlain = new Point2D(position, Dimention.Z); int stoneCount = 0; int wallCount = 0; int animalCount = 0; bool sameColorOfAllAnimal = true; Iterator iter = new Iterator(positOnPlain, 2); do { Point2D point = iter.Iter; Grid grid = World.GetAt(point.Binded); if (grid == null || grid.Obj == null) { continue; } else if (grid.Obj is Stone) { ++stoneCount; } else if (grid.Obj is Wall) { ++wallCount; } else if (grid.Obj is Animal && grid.Obj != this) { Animal animal = (Animal)grid.Obj; if (animal.Color.Equals(this.Color)) { if (animal.Hometown == null) { ++animalCount; } } else { sameColorOfAllAnimal = false; break; } } else if (grid.Obj is Creater) { Creater creater = (Creater)grid.Obj; this.ChangeHomeTown(creater); return; } } while (iter.MoveToNext()); if (sameColorOfAllAnimal && animalCount > 1) { Creater newHome = new Creater(position, this.Color); targetGrid.InsertObj(newHome); this.Hometown = newHome; GlobalAsset.creaters.Add(newHome); } }