private void Attack(XmlNode gang, Page page, AttackDifficulty difficulty) { System.Xml.XmlNode attackNode = attackDoc.CreateElement("Attack"); System.Xml.XmlAttribute targetId = attackDoc.CreateAttribute("TargetId"); System.Xml.XmlAttribute ETA = attackDoc.CreateAttribute("ETA"); System.Xml.XmlAttribute typeAttack = attackDoc.CreateAttribute("Type"); System.Xml.XmlAttribute attackerId = attackDoc.CreateAttribute("AttackerId"); targetId.Value = gang.Attributes["Id"].Value; attackerId.Value = "0"; DateTime d1 = new DateTime(1970, 1, 1).ToUniversalTime(); DateTime d2 = DateTime.UtcNow.AddHours(3 + rand.Next(0, 3)); DateTime d3 = DateTime.UtcNow; TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks); string arrival = ts.TotalMilliseconds.ToString(); ts = new TimeSpan(d3.Ticks - d1.Ticks); string now = ts.TotalMilliseconds.ToString(); ETA.Value = arrival; typeAttack.Value = "Zombies"; attackNode.Attributes.Append(targetId); attackNode.Attributes.Append(ETA); attackNode.Attributes.Append(typeAttack); attackNode.Attributes.Append(attackerId); attackDoc.LastChild.AppendChild(attackNode); int random = rand.Next(2, 5); int zombies = random * ((int)difficulty + 1); int exposure = System.Convert.ToInt32(gang.Attributes["Exposure"].Value); for (int i = 0; i < zombies; i++) { int exposureOffset = rand.Next(0, 50); System.Xml.XmlNode neutNode = attackDoc.CreateElement("Attacker"); System.Xml.XmlAttribute neutType = attackDoc.CreateAttribute("NeutType"); if (exposure < 55) neutType.Value = "Zombie"; else if (exposure < 85) neutType.Value = "PlagueZombie"; else if (exposure < 120) neutType.Value = "BloodZombie"; else neutType.Value = "ZombieLord"; neutNode.Attributes.Append(neutType); attackNode.AppendChild(neutNode); } gang.Attributes["LastAttack"].Value = now; gangDoc.Save(page.MapPath(@"~/LastStand/LastStandXml/Gang.xml")); attackDoc.Save(page.MapPath(@"~/LastStand/LastStandXml/Attacks.xml")); }
private void Attack(Gang gang, AttackDifficulty difficulty) { var attack = new Attack(); attack.Target = gang; attack.Attacker = null; DateTime d1 = new DateTime(1970, 1, 1).ToUniversalTime(); DateTime d2 = DateTime.UtcNow.AddHours(3 + rand.Next(0, 3)); DateTime d3 = DateTime.UtcNow; TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks); string arrival = ts.TotalMilliseconds.ToString(); ts = new TimeSpan(d3.Ticks - d1.Ticks); string now = ts.TotalMilliseconds.ToString(); attack.ETA.Value = arrival; attack.Indicator = "Zombies"; int random = rand.Next(2, 5); int zombies = random * ((int)difficulty + 1); int exposure = gang.Exposure; for (int i = 0; i < zombies; i++) { int exposureOffset = rand.Next(0, 50); var combatant = CombatantType.Zombie; if (exposure < 55) neutType.Value = CombatantType.Zombie; else if (exposure < 85) neutType.Value = CombatantType.Zombie; else if (exposure < 120) neutType.Value = CombatantType.Zombie; else neutType.Value = CombatantType.Zombie; neutNode.Attributes.Append(neutType); attackNode.AppendChild(neutNode); } gang.LastAttack = now; }
private void Attack(Gang gang, AttackDifficulty difficulty, ISession NhSession) { var attack = new Attack(); attack.Name = "Zombie attack"; attack.Target = gang; attack.Attacker = null; DateTime d1 = new DateTime(1970, 1, 1).ToUniversalTime(); DateTime d2 = DateTime.UtcNow.ToUniversalTime().AddHours(3 + rand.Next(0, 3)); DateTime d3 = DateTime.UtcNow.ToUniversalTime(); TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks); var arrival = ts.TotalMilliseconds; ts = new TimeSpan(d3.Ticks - d1.Ticks); var now = ts.TotalMilliseconds; attack.ETA = arrival; attack.Indicator = "Zombies"; int random = rand.Next(2, 5); int zombies = random * ((int)difficulty + 1); int exposure = gang.Exposure; for (int i = 0; i < zombies; i++) { int exposureOffset = rand.Next(0, 50); var combatant = CombatantType.Zombie; if (exposure < 55) combatant = CombatantType.Zombie; else if (exposure < 85) combatant = CombatantType.PlagueZombie; else if (exposure < 120) combatant = CombatantType.BloodZombie; else combatant = CombatantType.ZombieLord; attack.Combatants.Add(combatant); } gang.LastAttack = now; gang.IncomingAttacks.Add(attack); NhSession.Save(gang); NhSession.Save(attack); }