private void CancelEngagement(SimulationEvent e) { string targetObjectId = ((StringValue)e["TargetObjectID"]).value; string attackingObjectId = ((StringValue)e["AttackingObjectID"]).value; string capabilityName = ((StringValue)e["CapabilityName"]).value; for (int x = 0; x < this.currentAttacks.Count; x++) { if (currentAttacks[x].attacker == attackingObjectId && currentAttacks[x].target == targetObjectId && currentAttacks[x].capabilityName == capabilityName) { currentAttacks.RemoveAt(x); Attack tmp = new Attack(attackingObjectId, targetObjectId, capabilityName); tmp.SetTimes(currentAttacks[x].startTime,0); //remove in client view with tmp SendAttackEvent(tmp); return; } } }
/// <summary> /// /// </summary> /// <param name="e"></param> private void SelfDefenseAttackStarted(SimulationEvent e) { string attacker = ((StringValue)e["AttackerObjectID"]).value; string target = ((StringValue)e["TargetObjectID"]).value; if (DoesAttackListContainThisPair(attacker, target)) return; SimulationObjectProxy obj = objectProxies[attacker]; AttackCollectionValue attCV = (AttackCollectionValue)obj["CurrentAttacks"].GetDataValue(); List<AttackCollectionValue.AttackValue> selfDefenses = attCV.GetCurrentSelfDefenseAttacks(); AttackCollectionValue.AttackValue attackValue = null; if (selfDefenses.Count > 1) { Console.WriteLine("SelfDefenseAttackStarted, attacker contains more than one active self defense attack. -> " + selfDefenses.Count.ToString()); foreach (AttackCollectionValue.AttackValue av in selfDefenses) { if (av.attackingObjectId == attacker && av.targetObjectId == target) { attackValue = av; } } } else if(selfDefenses.Count == 1) { attackValue = selfDefenses[0]; } if (selfDefenses.Count == 0 || attackValue == null) return; //self defense not found int attackStart = attackValue.attackStartTime; int attackLength = attackValue.attackTimeWindow; Attack at = new Attack(attacker, target, attackValue.capabilityName); at.SetTimes(attackStart, attackLength); currentAttacks.Add(at); }
/// <summary> /// Add the given object to the CurrentAttacks list. At time ticks, ViewProAttackUpdates /// are sent out to clients using the attacks on the attack list. /// </summary> /// <param name="e">Incoming event</param> private void AttackObject(SimulationEvent e) { string attackingID = ((StringValue)e["ObjectID"]).value; string targetID = ((StringValue)e["TargetObjectID"]).value; string capabilityName = ((StringValue)e["CapabilityName"]).value; //int timeStart = ((IntegerValue)e["Time"]).value; SimulationObjectProxy obj = objectProxies[attackingID]; AttackCollectionValue attCV = (AttackCollectionValue)obj["CurrentAttacks"].GetDataValue(); AttackCollectionValue.AttackValue thisAttack = null; foreach (AttackCollectionValue.AttackValue av in attCV.GetCurrentAttacks()) { if (av.attackingObjectId == attackingID && av.capabilityName == capabilityName && av.targetObjectId == targetID) { //ignore time for now. thisAttack = av; } } if (thisAttack != null) { int timeStart = thisAttack.attackStartTime; int duration = thisAttack.attackTimeWindow; Attack theAttack = new Attack(attackingID, targetID, thisAttack.capabilityName); theAttack.SetTimes(timeStart, duration); currentAttacks.Add(theAttack); } else { //this is bad. } }