public WorldObjectResponse GetWorldObjects() { _worldObjects.RemoveAll(a => a.Removable && TypeComparer.IsSameOrVariant(typeof(Creature.Creature), a.GetType()).SuccessValue ? ((Creature.Creature)a).Hitpoints == 0 : false); return(new WorldObjectResponse( $"These are the objects in {this}", true, from worldObjects in _worldObjects select worldObjects)); }
public override double StandardModifier(IDamageType damageType) { if (TypeComparer.IsSameOrVariant(damageType.GetType(), typeof(FireDamageType)).SuccessValue) { return(0.5); } if (TypeComparer.IsSameOrVariant(damageType.GetType(), typeof(WaterDamageType)).SuccessValue) { return(0.1); } return(1); }
/// <summary> /// Unequips a given item, if it is equipped. /// </summary> /// <param name="item">item is the item that is to be unequipped</param> /// <returns>Returns a EquipItemResponse to describe the operation.</returns> public virtual EquipItemResponse DeEquipItem(IWearable item) { Type itemType = item.GetType(); if (TypeComparer.IsSameOrVariant(typeof(IAttackItem), itemType).SuccessValue) { return(RemoveItem <IAttackItem>(AttackItems, (IAttackItem)item, _defaultAttackItem)); } if (TypeComparer.IsSameOrVariant(typeof(IDefenseItem), itemType).SuccessValue) { return(RemoveItem <IDefenseItem>(DefenseItems, (IDefenseItem)item, _defaultDefenseItem)); } return(RemoveItem <IWearable>(MiscItems, item, _defaultMiscItem)); }
static void Main(string[] args) { GameEngineWorker engine = new GameEngineWorker(); engine.AddObject(new Boulder("Rock", new Position(47, 47, 1, 1))); engine.AddObject(new HumanoidConcreteFactory(1, "nobody", new Position(45, 45, 1, 1)).MakeCreature()); Creature derp = new HumanoidCreature(20, 3000, new ItemManager(new Inventory(), new HumanoidLoadOut(new HumanoidSlots(), new HumanoidSkin("skin", new IDamageType[] { new PhysicalDamageType(), }))), "DERP", false, new Position(45, 50, 1, 1), new BoarLootTableDecorator(new HumanoidLootTableDecorator(new LootTable()))); engine.AddObject(derp); derp.ItemManager.GearLoadOut.AttackItems["fist"] = new Sword(new IDamageType[] { new RangeDamageType(), }, 20); engine.AddObject(new Boulder("Rock", new Position(51, 51, 2, 1))); engine.AddObject(new Boulder("Rock", new Position(55, 55, 2, 2))); Human gert = new Human("Henrik", new Position(50, 50, 1, 1)); engine.AddObject(gert); engine.Player = gert; engine.Player.ItemManager.AddItems(new ItemsResponse("", "", new[] { new Sword(new IDamageType[] { new FireDamageType() }, 200), })); engine.Player.ItemManager.EquipGear((IWearable)engine.Player.ItemManager.Inventory.GetItems().Value .First(a => TypeComparer.IsSameOrVariant(typeof(IAttackItem), a.GetType()).SuccessValue)); var map = engine.GetPlayerSurroundings(vision); PrintMap(map); while (true) { var KeyPress = Console.ReadKey(true); if (KeyPressed(KeyPress, engine.Player, map)) { if (engine.Player.Hitpoints > 0) { Console.Clear(); map = engine.GetPlayerSurroundings(vision); PrintMap(map); Thread.Sleep(100); } } } }
public static DamageResponse TransformDamage(DamageResponse attack, double efficiency) { Random random = new Random(DateTime.Now.Millisecond); var allAttackTypes = from attackTypes in attack.DamageSource.DamageTypes select attackTypes; var physicalTypes = from attackTypes in attack.DamageSource.DamageTypes where TypeComparer.IsSameOrVariant(typeof(PhysicalDamageType), attackTypes.GetType()).SuccessValue select attackTypes; double physicalPercent = (from weights in physicalTypes select weights.Weight).Sum() / (from weights in allAttackTypes select weights.Weight).Sum(); if (physicalPercent == 0) { return(attack); } //todo damage skal regnes så plate fjerne noget af physical skaden. if (physicalPercent > random.NextDouble()) { } attack.Damage = (attack.Damage * physicalPercent) + (attack.Damage * (1 - physicalPercent)); return(null); }
static void PrintMap(WorldObject[][] map) { List <string> stringLinesMap = new List <string>(); for (int i = 0; i < map.First().Length; i++) { StringBuilder newLine = new StringBuilder(); foreach (var width in map) { WorldObject coordinate = width[i]; if (coordinate is null) { newLine.Append(" "); } else if (TypeComparer.IsSameOrVariant(typeof(Human), coordinate.GetType(), true).SuccessValue) { newLine.Append("O"); } else if (TypeComparer.IsSameOrVariant(typeof(Creature), coordinate.GetType(), true).SuccessValue) { newLine.Append("X"); } else { newLine.Append("@"); } } stringLinesMap.Add(newLine.ToString()); } stringLinesMap.Reverse(); foreach (var line in stringLinesMap) { Console.WriteLine(line); } }
public override Creature MakeCreature() { BoarCreature creature = new BoarCreature( _level, 20 * (_level), new ItemManager( new Inventory(), new GearLoadOut( new BoarSlots(), new Hide(null))), _name ?? "boar", true, _position ?? new Position(1, 1, 1, 2), new BoarLootTableDecorator(new LootTable())); creature.ItemManager.AddItems(new ItemsResponse("Adding start items.", $"{GetType().Name}", new IItem[] { new Hide(null), new Hoofs(null), new TuskWeapon(null) })); creature.ItemManager.GetItems().Value.Where(a => TypeComparer.IsSameOrVariant(typeof(IWearable), a.GetType()).SuccessValue) .ToList().ForEach(a => { creature.ItemManager.EquipGear((IWearable)a); }); return(creature); }
static void Main(string[] args) { TraceSourceSingleton.Ts().Listeners.Add(new ConsoleTraceListener()); TraceSourceSingleton.Ts().Listeners.Add(new TextWriterTraceListener(new StreamWriter("Tracing.txt"))); TraceSourceSingleton.Ts().Listeners.Add(new DefaultTraceListener()); TraceSourceSingleton.Ts().Listeners.Add(new XmlWriterTraceListener("XMLTracing.xml")); World newWorld = new World(new WorldObjectManager()); Creature human = (new HumanoidConcreteFactory(1, "Man")).MakeCreature(); newWorld.AddWorldObjectToWorld(human); WorldObject obj = newWorld.WorldObjectsManager.GetWorldObjects().WorldObjects.First(); if (TypeComparer.IsSameOrVariant(typeof(Creature), obj.GetType()).SuccessValue) { ((Creature)obj).ItemManager.AddItems(new ItemsResponse("Adding item", "GOD", new [] { new Sword(new[] { new PhysicalDamageType() }, 5) })); ((Creature)obj).ItemManager.EquipGear((IAttackItem)((Creature)obj).ItemManager.GetItems().Value.First()); while (true) { IResponse response = ((Creature)obj).ReceiveHit(((Creature)obj).Hit()); if (response.SuccessValue == false && TypeComparer .IsSameOrVariant(typeof(WorldObjectResponse), response.GetType()).SuccessValue) { Console.WriteLine("woops"); break; } if (response.SuccessValue) { Console.WriteLine("BONK"); } Console.ReadLine(); } Thread.Sleep(3000); ItemsResponse itemsLoot = ((Creature)obj).Loot(); string collectedLoot = ""; itemsLoot.Value.ToList().ForEach(a => collectedLoot += a.Name + " "); Console.WriteLine("WAUW you've looted : " + collectedLoot); Console.ReadLine(); Console.WriteLine("now new dude with armor, and bigg sword vs small dude"); Creature bigGuyCreature = (new HumanoidConcreteFactory(5, "BIGG GUY")).MakeCreature(); Creature smoll = (new HumanoidConcreteFactory(1)).MakeCreature(); bigGuyCreature.ItemManager.Inventory.AddItems(new ItemsResponse("Adding startup items", "GOD", new IItem[] { new BreastArmor(10, new[] { new PhysicalDamageType(), }), new HeadArmor(5, new[] { new PhysicalDamageType(), }), new Sword(new IDamageType[] { new PhysicalDamageType(), new FireDamageType(2) }, 10) })); bigGuyCreature.ItemManager.Inventory.GetItems().Value.Where(a => TypeComparer.IsSameOrVariant(typeof(IWearable), a.GetType()).SuccessValue).ToList().ForEach(a => { bigGuyCreature.ItemManager.GearLoadOut.EquipItem((IWearable)a); }); smoll.ItemManager.AddItems(new ItemsResponse("Adding startup items", "GOD", new IItem[] { new BreastArmor(13, new IDamageType[] { new PhysicalDamageType(), new FireDamageType(), }), new HeadArmor(15, new IDamageType[] { new PhysicalDamageType(), new FireDamageType() }), new Sword(new IDamageType[] { new PhysicalDamageType() }, 5), })); smoll.ItemManager.Inventory.GetItems().Value.Where(a => TypeComparer.IsSameOrVariant(typeof(IWearable), a.GetType()).SuccessValue).ToList().ForEach(a => { smoll.ItemManager.GearLoadOut.EquipItem((IWearable)a); }); Console.WriteLine("AIT FIGHT BOIS"); bool oneAlive = true; while (oneAlive) { oneAlive = smoll.ReceiveHit(bigGuyCreature.Hit()).SuccessValue&& oneAlive; if (oneAlive) { oneAlive = bigGuyCreature.ReceiveHit(smoll.Hit()).SuccessValue&& oneAlive; } } if (smoll.Hitpoints > 0) { smoll.ItemManager.AddItems(bigGuyCreature.Loot()); } else { bigGuyCreature.ItemManager.AddItems(smoll.Loot()); } } }
static bool KeyPressed(ConsoleKeyInfo keyPress, Creature player, WorldObject[][] map) { WorldObject objInfront; switch (keyPress.Key) { case ConsoleKey.LeftArrow: objInfront = map[vision - 1][vision]; if (objInfront is null) { player.Move(-1, 0); } else { if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue) { Creature creature = (Creature)objInfront; DamageResponse attack = player.Hit(); IResponse response = creature.ReceiveHit(attack); if (!response.SuccessValue) { player.ItemManager.AddItems(creature.Loot()); } else { response = player.ReceiveHit(creature.Hit()); if (!response.SuccessValue) { Console.Clear(); Console.WriteLine("YOU DIED"); } } } } break; case ConsoleKey.RightArrow: objInfront = map[vision + 1][vision]; if (objInfront is null) { player.Move(1, 0); } else { if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue) { Creature creature = (Creature)objInfront; DamageResponse attack = player.Hit(); IResponse response = creature.ReceiveHit(attack); if (!response.SuccessValue) { player.ItemManager.AddItems(creature.Loot()); } else { response = player.ReceiveHit(creature.Hit()); if (!response.SuccessValue) { Console.Clear(); Console.WriteLine("YOU DIED"); } } } } break; case ConsoleKey.UpArrow: objInfront = map[vision][vision + 1]; if (objInfront is null) { player.Move(0, 0 + 1); } else { if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue) { Creature creature = (Creature)objInfront; DamageResponse attack = player.Hit(); IResponse response = creature.ReceiveHit(attack); if (!response.SuccessValue) { player.ItemManager.AddItems(creature.Loot()); } else { response = player.ReceiveHit(creature.Hit()); if (!response.SuccessValue) { Console.Clear(); Console.WriteLine("YOU DIED"); } } } } break; case ConsoleKey.DownArrow: objInfront = map[vision][vision - 1]; if (objInfront is null) { player.Move(0, -1); } else { if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue) { Creature creature = (Creature)objInfront; DamageResponse attack = player.Hit(); IResponse response = creature.ReceiveHit(attack); if (!response.SuccessValue) { player.ItemManager.AddItems(creature.Loot()); } else { response = player.ReceiveHit(creature.Hit()); if (!response.SuccessValue) { Console.Clear(); Console.WriteLine("YOU DIED"); } } } } break; default: return(false); } return(true); }