public static void Attack(ICreature attacker, ICreature deffender, int answer) { //Chance of armor deflecting the attack //If armor doesnt stop the attack. if (RandomChance.Success(100 - deffender.Armor)) { //Chance of dealing damage. int damageDealth = attacker.Attack(attacker.AttackChance[answer], attacker.AttackPower[answer]); //If any damage dealth if (damageDealth != 0) { deffender.HP -= damageDealth; //If defender is dead. if (deffender.HP > 0) { Console.WriteLine($"{attacker.Name} dealth {damageDealth} damage. {deffender.Name} now has {deffender.HP}HP"); } else { Console.WriteLine("{1} dealth {0} damage.", damageDealth, attacker.Name); } } //No damage dealth. else { //Attack failed Console.WriteLine("{1} couldn't perform {0}.", attacker.AttackNames[answer], attacker.Name); } } else { //armor blocked Console.WriteLine("{0}'s armor stopped {1} attack.", deffender.Name, attacker.Name); } }
public void It_should_create_a_random_chance() { var randomChance = new RandomChance { chance = 1, outOf = 2 }; Assert.IsNotNull(randomChance.Update()); }
void Start() { conditions = GetComponents <AiConditionBase>(); conditionChance = new RandomChance(); conditionChance.chances = new float[conditions.Length]; myFraction = GetComponentInParent <AiFraction>(); myPerception = GetComponentInParent <AiPerception>(); }
//methods public int Attack(int chance, double multiplier) { //80% chance for a strike if (RandomChance.Success(chance)) { return(Convert.ToInt32(this.Damage * multiplier)); } else { return(0); } }
public int StrongAttack() { //55% chance for a strike if (RandomChance.Success(55)) { return(this.Damage); } else { return(0); } }
public int UltimateAttack() { //30% chance for a strike if (RandomChance.Success(30)) { return(this.Damage * 2); } else { return(0); } }
public int WeakAttack() { //80% chance for a strike if (RandomChance.Success(80)) { return(this.Damage / 2); } else { return(0); } }
public override void WriteDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (EditorID != null) { ele.TryPathTo("EditorID", true, out subEle); EditorID.WriteXML(subEle, master); } if (ObjectBounds != null) { ele.TryPathTo("ObjectBounds", true, out subEle); ObjectBounds.WriteXML(subEle, master); } if (Filename != null) { ele.TryPathTo("Filename", true, out subEle); Filename.WriteXML(subEle, master); } if (RandomChance != null) { ele.TryPathTo("RandomChance", true, out subEle); RandomChance.WriteXML(subEle, master); } if (SoundData != null) { ele.TryPathTo("SoundData", true, out subEle); SoundData.WriteXML(subEle, master); } if (SoundDataShort != null) { ele.TryPathTo("SoundDataShort", true, out subEle); SoundDataShort.WriteXML(subEle, master); } if (AttenuationCurve != null) { ele.TryPathTo("AttenuationCurve", true, out subEle); AttenuationCurve.WriteXML(subEle, master); } if (ReverbAttenuationControl != null) { ele.TryPathTo("ReverbAttenuationControl", true, out subEle); ReverbAttenuationControl.WriteXML(subEle, master); } if (SoundPriority != null) { ele.TryPathTo("SoundPriority", true, out subEle); SoundPriority.WriteXML(subEle, master); } }
public override void WriteData(ESPWriter writer) { if (EditorID != null) { EditorID.WriteBinary(writer); } if (ObjectBounds != null) { ObjectBounds.WriteBinary(writer); } if (Filename != null) { Filename.WriteBinary(writer); } if (RandomChance != null) { RandomChance.WriteBinary(writer); } if (SoundData != null) { SoundData.WriteBinary(writer); } if (SoundDataShort != null) { SoundDataShort.WriteBinary(writer); } if (AttenuationCurve != null) { AttenuationCurve.WriteBinary(writer); } if (ReverbAttenuationControl != null) { ReverbAttenuationControl.WriteBinary(writer); } if (SoundPriority != null) { SoundPriority.WriteBinary(writer); } }
public override void ReadData(ESPReader reader, long dataEnd) { while (reader.BaseStream.Position < dataEnd) { string subTag = reader.PeekTag(); switch (subTag) { case "EDID": if (EditorID == null) { EditorID = new SimpleSubrecord <String>(); } EditorID.ReadBinary(reader); break; case "OBND": if (ObjectBounds == null) { ObjectBounds = new ObjectBounds(); } ObjectBounds.ReadBinary(reader); break; case "FNAM": if (Filename == null) { Filename = new SimpleSubrecord <String>(); } Filename.ReadBinary(reader); break; case "RNAM": if (RandomChance == null) { RandomChance = new SimpleSubrecord <Byte>(); } RandomChance.ReadBinary(reader); break; case "SNDD": if (SoundData == null) { SoundData = new SoundData(); } SoundData.ReadBinary(reader); break; case "SNDX": if (SoundDataShort == null) { SoundDataShort = new SoundDataShort(); } SoundDataShort.ReadBinary(reader); break; case "ANAM": if (AttenuationCurve == null) { AttenuationCurve = new SoundAttenuation(); } AttenuationCurve.ReadBinary(reader); break; case "GNAM": if (ReverbAttenuationControl == null) { ReverbAttenuationControl = new SimpleSubrecord <Int16>(); } ReverbAttenuationControl.ReadBinary(reader); break; case "HNAM": if (SoundPriority == null) { SoundPriority = new SimpleSubrecord <Int32>(); } SoundPriority.ReadBinary(reader); break; default: throw new Exception(); } } }
public override void ReadDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (ele.TryPathTo("EditorID", false, out subEle)) { if (EditorID == null) { EditorID = new SimpleSubrecord <String>(); } EditorID.ReadXML(subEle, master); } if (ele.TryPathTo("ObjectBounds", false, out subEle)) { if (ObjectBounds == null) { ObjectBounds = new ObjectBounds(); } ObjectBounds.ReadXML(subEle, master); } if (ele.TryPathTo("Filename", false, out subEle)) { if (Filename == null) { Filename = new SimpleSubrecord <String>(); } Filename.ReadXML(subEle, master); } if (ele.TryPathTo("RandomChance", false, out subEle)) { if (RandomChance == null) { RandomChance = new SimpleSubrecord <Byte>(); } RandomChance.ReadXML(subEle, master); } if (ele.TryPathTo("SoundData", false, out subEle)) { if (SoundData == null) { SoundData = new SoundData(); } SoundData.ReadXML(subEle, master); } if (ele.TryPathTo("SoundDataShort", false, out subEle)) { if (SoundDataShort == null) { SoundDataShort = new SoundDataShort(); } SoundDataShort.ReadXML(subEle, master); } if (ele.TryPathTo("AttenuationCurve", false, out subEle)) { if (AttenuationCurve == null) { AttenuationCurve = new SoundAttenuation(); } AttenuationCurve.ReadXML(subEle, master); } if (ele.TryPathTo("ReverbAttenuationControl", false, out subEle)) { if (ReverbAttenuationControl == null) { ReverbAttenuationControl = new SimpleSubrecord <Int16>(); } ReverbAttenuationControl.ReadXML(subEle, master); } if (ele.TryPathTo("SoundPriority", false, out subEle)) { if (SoundPriority == null) { SoundPriority = new SimpleSubrecord <Int32>(); } SoundPriority.ReadXML(subEle, master); } }