public override IEnumerable <AGameEvent> Think(List <Contracts.GameObject.AGameObject> gameObjects, System.Collections.Generic.List <Contracts.GameObject.AGameObject> newGameObjects, long time) { var res = new List <AGameEvent>(); if (_parent != null && !_parent.IsActive) { _parent = null; } if (_childBornTime == -1) { _childBornTime = time; } if ((_child == null || !_child.IsActive) && time - _childBornTime > Constants.CATERPILLAR_CHILD_BORN_INTERVAL) { _child = new Caterpillar(MaxHealthAmount, this); MaxHealthAmount *= 1.05f; HealthAmount *= 1.05f; Radius *= 1.05f; _child.Coordinates = Coordinates + (-RunVector) * (_child.Radius + Radius); newGameObjects.Add(_child); res.Add(new NewObjectEvent(_child, time)); } if (_parent == null) { res.AddRange(base.Think(gameObjects, newGameObjects, time)); if (Target != null) { //if(Vector2.DistanceSquared()) { RunVector = (Target.Coordinates + (new Vector2(RunVector.Y, -RunVector.X)) * (Target.Radius + Radius)) - Coordinates; } //else //{ // RunVector = (Target.Coordinates + new Vector2(RunVector.Y, -RunVector.X)) - Coordinates; //} RunVector.Normalize(); } } else { RunVector = _parent.Coordinates - Coordinates; RunVector.Normalize(); } ShootVector = RunVector; return(res); }
public override IEnumerable <AGameEvent> Think(List <AGameObject> gameObjects, List <AGameObject> newGameObjects, long time) { var r = new List <AGameEvent>(base.Think(gameObjects, newGameObjects, time)); if (RunVector.LengthSquared() < Constants.EPSILON && Wait < 1) //&& PrevMoveDiff.LengthSquared() < Constants.Epsilon) { //the object is trying to move, but it can't // i.e a wall or another mob exist on the path to <b>Target</b> var l = new List <AGameObject>(); AGameObject nearest = null; // set to the max distance on the game float minLen = Constants.LEVELBORDER * Constants.LEVELBORDER; for (int i = 0; i < gameObjects.Count; i++) { var p = gameObjects[i]; // myself if (TeamIdentity == p.TeamIdentity || p.Is(EnumObjectType.Bonus) || p.Is(EnumObjectType.Bullet)) { continue; } float len = (p.Coordinates - Coordinates).Length(); if (len < 4 * (p.Radius + Radius)) { l.Add(p); } else { // no sence to look at far objects continue; } if (len < minLen) { minLen = len; nearest = p; } } if (nearest != null && Target != null && nearest != Target) { var toObject = nearest.Coordinates - Coordinates; var toTarget = Target.Coordinates - Coordinates; toObject.Normalize(); toTarget.Normalize(); ThinkCounter = 0; //!! evristic Wait = (int)Math.Floor(Radius * 1f); //var angle = Math.Acos(Vector2.Dot(toOnject, toTarget)); //if(angle < 0) //{ // RunVector = new Vector2(RunVector.Y, -RunVector.X); //} //else //{ // RunVector = new Vector2(-RunVector.Y, RunVector.X); //} RunVector = toTarget - toObject; RunVector.Normalize(); } } return(r); }
public override IEnumerable <AGameEvent> Do(AGameObject obj, List <AGameObject> newObjects, long time) { var res = new List <AGameEvent>(base.Do(obj, newObjects, time)); if (Owner.TeamIdentity == obj.TeamIdentity && obj.Is(EnumObjectType.LivingObject) && !obj.Is(EnumObjectType.Poisoning)) //Препятствия не должны пролетаться насквозь { return(res); } if (obj.Is(EnumObjectType.LivingObject)) { var owner = Owner as MainSkyShootService; var damageMod = 1f; if (obj.Is(EnumObjectType.Player)) { var player = obj as MainSkyShootService; if (player != null) { var mirror = player.GetBonus(EnumObjectType.Mirror); if (mirror != null && !_mirrored) { RunVector = -RunVector; RunVector.Normalize(); // some times we have strange errors with length of run and shoot vectors ShootVector = RunVector; res.Add(new ObjectDirectionChanged(RunVector, Id, time)); _mirrored = true; return(res); } var shield = player.GetBonus(EnumObjectType.Shield); damageMod = shield == null ? 1f : shield.DamageFactor; } } var dmg = Math.Min(obj.HealthAmount, Damage * damageMod); obj.HealthAmount -= Damage * damageMod; #region Изменение статистики if (owner != null) { int teamMembers = owner.TeamIdentity.Members.Count; owner.Tracker.AddExpPlayer(owner, obj, (int)(dmg)); foreach (AGameObject member in owner.TeamIdentity.Members) { var player = member as MainSkyShootService; Debug.Assert(player != null); player.Tracker.AddExpTeam(player, obj, (int)(dmg), teamMembers); } } #endregion res.Add(new ObjectHealthChanged(obj.HealthAmount, obj.Id, time)); // убираем пулю IsActive = false; } if (obj.Is(EnumObjectType.Wall)) { IsActive = false; } if (!IsActive) { res.Add(new ObjectDeleted(Id, time)); } return(res); }