public void InitializeAI(Agent.Creature creature, OperacjeMapy.Pole[,] mapa) { if (creature.attributes.AIType == AILoop.AIType.BasicAi) { Console.WriteLine("My AI is BasicAi: {0}", creature.name); var stateMachine = new StateMachineBasic(); var ai = new BasicAIDij(); if (creature.attributes.HP < creature.attributes.morale) { stateMachine.ProcessEvent(StateMachineBasic.Events.HPLow); } var enemies = new EnemiesInSight(mapa, creature); if (enemies.enemiesInSight.Count != 0) { stateMachine.ProcessEvent(StateMachineBasic.Events.EnemyInSight); Console.WriteLine("Theres {1} enemy in sight. My current state is {2}: {0}", creature.name, enemies.enemiesInSight.Count, stateMachine.State); ai.Attack(creature, mapa, enemies.enemiesInSight[0]); } else { stateMachine.ProcessEvent(StateMachineBasic.Events.NoEnemyInSight); } Needs.CheckNeeds.CheckCreaturesNeeds(creature); if (stateMachine.State == StateMachineBasic.States.Roaming) { ai.Roam(creature, mapa); } //Console.WriteLine(" My current state is {1}: {0}", creature.name, stateMachine.State); } }
public Group(Agent.Creature leader) { this.leader = leader; this.members = new List <Agent.Creature>(); this.members.Add(leader); this.headquarters = new Place(); }
public void MakeCreaturesList() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("Creatures.xml"); XmlNodeList elemList = xmlDoc.GetElementsByTagName("creature"); Console.WriteLine("Number of creatures: {0}", elemList.Count); for (int i = 0; i < elemList.Count; i++) { var creature = new Agent.Creature(); Console.WriteLine("Adding creature no. {0}", i); creature.type = elemList[i].Attributes["type"].Value[0]; Console.WriteLine("Creature type: {0}", creature.type); creature.name = elemList[i].Attributes["name"].Value; creature.attributes.fighting = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.bravery = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.charisma = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.agility = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.initiative = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.inteligence = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.strength = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.morale = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.visualrange = byte.Parse(elemList[i].Attributes["fighting"].Value); creature.attributes.AIType = AILoop.AIType.BasicAi; creaturesList.Add(creature); } }
public Agent.Creature MakeCreature(Agent.Creature creature, string name, byte HP, byte fighting, char type, byte bravery, byte charisma, byte agility, byte initiative, byte inteligence, byte strength, byte morale, byte visualrange, AILoop.AIType aiType ) { creature.attributes.AIType = aiType; creature.attributes.bravery = bravery; creature.attributes.charisma = charisma; creature.attributes.agility = agility; creature.attributes.HP = HP; creature.attributes.initiative = initiative; creature.attributes.inteligence = inteligence; creature.attributes.morale = morale; creature.attributes.strength = strength; creature.attributes.fighting = fighting; creature.name = name; creature.type = type; creature.attributes.visualrange = visualrange; return(creature); }
public MapEntity() { this.passable = true; this.transluscent = true; this.HP = 100; this.family = "Null_family"; this.owner = new Agent.Creature(); this.resourcesRequired = new List <ResourceRequirement>(); }
public void SpawnWeapons(Agent.Creature creature, Agent.Weapon weapon, OperacjeMapy.Pole[,] map) { for (int i = 0; i < map[creature.currentpossition.X, creature.currentpossition.Y].Creature.Count; i++) { if (map[creature.currentpossition.X, creature.currentpossition.Y].Creature[i] == creature) { map[creature.currentpossition.X, creature.currentpossition.Y].Creature[i].inventory.Add(weapon); } } Console.WriteLine("Spawning {0} to {1}s inventory.", weapon.name, creature.name); }
public MapEntity(MapEntity entity) { this.family = entity.family; this.HP = entity.HP; this.name = entity.name; this.passable = entity.passable; this.transluscent = entity.transluscent; this.type = entity.type = type; this.owner = entity.owner; this.resourcesRequired = entity.resourcesRequired; }
public EnemiesInSight(OperacjeMapy.Pole[,] mapa, Agent.Creature creature) { creatureFOV = new GetFOV(mapa, creature); enemiesInSight = new List <Agent.Creature>(); creatureFOV.GetMyFOV(); foreach (Point p in creatureFOV.FOVCalc.VisiblePoints) { foreach (Agent.Creature kreatura in mapa[p.X, p.Y].Creature) { if (kreatura.name == "player") { enemiesInSight.Add(kreatura); Console.WriteLine("Adding {0} to enemies", kreatura.name); } } } }
public OperacjeMapy.Pole[,] InsertCreature(Agent.Creature creature, int x, int y, OperacjeMapy.Pole[,] mapa) { if (!mapa[x, y].passable) { Console.WriteLine("W polu o współrzędnych [{0},{1}] nie można wstawić agenta. \nPodaj nowe współrzędne:", x, y); int k, j; k = Convert.ToInt16(Console.ReadLine()); j = Convert.ToInt16(Console.ReadLine()); InsertCreature(creature, --k, --j, mapa); } else { creature.currentpossition = new Point(x, y); mapa[x, y].Creature.Add(creature); mapa[x, y].passable = false; Console.WriteLine("wsadzam na pozycji [{0}] [{1}] ", creature.currentpossition.X, creature.currentpossition.Y); } return(mapa); }
public Fight(Agent.Creature attacker, Agent.Creature defender) { var mechanics = new FightingMechanics(); List <FightingMechanics.CombatParam> attToHit = new List <FightingMechanics.CombatParam>(); List <FightingMechanics.CombatParam> defToHit = new List <FightingMechanics.CombatParam>(); List <FightingMechanics.CombatParam> atToDmg = new List <FightingMechanics.CombatParam>(); FightingMechanics.CombatParam combatParam = new FightingMechanics.CombatParam(); combatParam.param = attacker.attributes.strength; combatParam.weight = 0.2; atToDmg.Add(combatParam); combatParam.param = attacker.attributes.fighting; combatParam.weight = 1; attToHit.Add(combatParam); combatParam.param = attacker.attributes.agility; combatParam.weight = 0.5; attToHit.Add(combatParam); combatParam.param = defender.attributes.fighting; combatParam.weight = 1; defToHit.Add(combatParam); combatParam.param = defender.attributes.agility; combatParam.weight = 0.5; defToHit.Add(combatParam); var attDmgRoll = mechanics.DamageRoll(atToDmg); var DidItHit = mechanics.DidItHit(attToHit, defToHit); if (DidItHit) { //event hit } else { //event missed which shows message and logs it } }
public void Run(Agent.Creature creature, Point chaserPos, OperacjeMapy.Pole[,] mapa) { var ai = new BasicAIDij(); var random = new Random(); var r = creature.currentpossition; var c = chaserPos; var vectorX = r.X - c.X; var vectorY = r.Y - c.Y; var adjPassPoints = GetAdjecentPassablePoints(mapa, r); var escapeTo = new Point(r.X + vectorX, r.Y + vectorY); if (adjPassPoints.Contains(escapeTo)) { ai.GoTo(r, escapeTo, mapa, creature); } else { var rand = random.Next(0, adjPassPoints.Count); ai.GoTo(r, adjPassPoints[rand], mapa, creature); } }
public OperacjeMapy.Pole[,] GoTo(Point startPos, Point endPos, OperacjeMapy.Pole[,] map2, Agent.Creature creature) { Point start = new Point { X = startPos.X, Y = startPos.Y }; Point end = new Point { X = endPos.X, Y = endPos.Y }; /* * for (int i = 0; i < map.GetLength(0); i++) { * for (int j = 0; j < map.GetLength(1); j++) { * if(map[i,j]) Console.Write("0"); else Console.Write("1"); * * } * Console.WriteLine(); * * } */ //Console.WriteLine("Init Dij"); Dijkstra dij = new Dijkstra(); SetMap(map2); dij.InitializeMap(mapSize.Height, mapSize.Width, start, end, passMap); //Console.WriteLine("Map inited"); var path = new List <Point>(); path = dij.FindPath(); //Console.WriteLine("Path Found"); /*foreach (Point p in path){ * Console.Write("[{0}] [{1}] || ",p.X,p.Y); * } * * for (int j = 0; j < map2.GetLength(1); j++) { * for (int i = 0; i < map2.GetLength(0); i++) { * map2[i,j].colour = ConsoleColor.White; * } * * } * * * for (int i = 0; i < path.Count; i++) { * map2[path[i].X,path[i].Y].colour = ConsoleColor.DarkMagenta; * } */ CreatureActions actuator = new CreatureActions(); if (path.Count > 0) { Point moveto = new Point(path[0].X, path[0].Y); map2 = actuator.MoveCreature(moveto, map2, creature); } return(map2); }
public void DrawCommandMenu(List <Agent.Weapon> wpnList, List <Agent.Creature> crtList, OperacjeMapy.Pole[,] mapa, List <Agent.Resource> resourcesList) { Point coords; bool coordsIsOK = true; while (input != "1") { Console.WriteLine("\n"); Console.WriteLine("1. Exit command menu."); Console.WriteLine("2. Spawn an item."); Console.WriteLine("3. Spawn a creature."); Console.WriteLine("4. Spawn a mapEntity."); input = Console.ReadLine(); switch (input) { case "1": { break; } case "2": { var spawner = new ItemSpawner(); string whichItem; Console.WriteLine("Which kind of item would you like to spawn?\n 1.Weapon\n 2.null"); whichItem = Console.ReadLine(); switch (whichItem) { case "1": { Console.WriteLine("Which weapon would you like to spawn (type in ID number for answer):"); int i = 0; foreach (Agent.Weapon wpn in wpnList) { Console.WriteLine("ID: {4}\t{0}\tMinDamage: {1}\tMaxDamage: {2}\tWeaponLength: {3}\n", wpn.name, wpn.minDamage, wpn.maxDamage, wpn.weaponLength, i); i++; } int wpnID = Convert.ToInt16(Console.ReadLine()); var answerWeapon = new Agent.Weapon(); answerWeapon = wpnList[wpnID]; Console.WriteLine("Would you like to spawn the weapon to a creatures inventory(1) or on the map(2)?"); string answer = Console.ReadLine(); switch (answer) { case "1": { break; } case "2": { //do{ Console.WriteLine("Where would you like to spawn the weapon (coord x and y):"); int x, y; x = Convert.ToInt16(Console.ReadLine()); y = Convert.ToInt16(Console.ReadLine()); coords = new Point(y--, x--); spawner.SpawnWeapons(coords, answerWeapon, mapa); //}while(coordsIsOK); break; } default: { break; } } break; } case "2": { break; } } break; } case "3": { var spawner = new CreatureSpawner(); Console.WriteLine("Which creature would you like to spawn (type in ID number for answer):"); int i = 0; foreach (Agent.Creature crt in crtList) { Console.WriteLine("ID: {1}\t{0}\n", crt.name, i); i++; } int crtID = Convert.ToInt16(Console.ReadLine()); var answerCreature = new Agent.Creature(); answerCreature = crtList[crtID]; //do{ Console.WriteLine("Where would you like to spawn the creature (coord x and y):"); int x, y; x = Convert.ToInt16(Console.ReadLine()); y = Convert.ToInt16(Console.ReadLine()); coords = new Point(y--, x--); spawner.SpawnCreature(coords, answerCreature, mapa); //}while(coordsIsOK); break; } default: { break; } } break; } }
public OperacjeMapy.Pole[,] MoveCreature(Point whereTo, OperacjeMapy.Pole[,] mapa, Agent.Creature creature) { mapa[whereTo.X, whereTo.Y].Creature.Add(creature); mapa[whereTo.X, whereTo.Y].passable = false; Console.WriteLine(); Console.WriteLine("Adding creature to [{0}],[{1}]", whereTo.X, whereTo.Y); mapa[creature.currentpossition.X, creature.currentpossition.Y].Creature.Remove(creature); mapa[creature.currentpossition.X, creature.currentpossition.Y].passable = true; Console.WriteLine("Removing creature from [{0}],[{1}]", creature.currentpossition.X, creature.currentpossition.Y); mapa[whereTo.X, whereTo.Y].Creature[0].currentpossition = whereTo; Console.WriteLine("Adding currposs [,] to [{0}],[{1}]", creature.currentpossition.X, creature.currentpossition.Y); return(mapa); }
public GetFOV(OperacjeMapy.Pole[,] tab, Agent.Creature creature) { FOVCalc = new FOVRecurse(); this.tab = tab; this.creature = creature; }
public void Attack(Agent.Creature attacker, OperacjeMapy.Pole[,] mapa, Agent.Creature defender) { BasicAIDij ai = new BasicAIDij(); Random r = new Random(); int damageDone = r.Next(1, 10); bool defenderIsAdjacent; int aPX = attacker.currentpossition.X; int aPY = attacker.currentpossition.Y; int dPX = defender.currentpossition.X; int dPY = defender.currentpossition.Y; if (aPX - 1 == dPX && aPY == dPY) { defenderIsAdjacent = true; } else if (aPX + 1 == dPX && aPY == dPY) { defenderIsAdjacent = true; } else if (aPX == dPX && aPY + 1 == dPY) { defenderIsAdjacent = true; } else if (aPX == dPX && aPY - 1 == dPY) { defenderIsAdjacent = true; } else if (aPX - 1 == dPX && aPY - 1 == dPY) { defenderIsAdjacent = true; } else if (aPX - 1 == dPX && aPY + 1 == dPY) { defenderIsAdjacent = true; } else if (aPX + 1 == dPX && aPY - 1 == dPY) { defenderIsAdjacent = true; } else if (aPX + 1 == dPX && aPY + 1 == dPY) { defenderIsAdjacent = true; } else { defenderIsAdjacent = false; } if (defenderIsAdjacent) { Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent); Console.WriteLine("Hadzia!"); } else { Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent); ai.GoTo(attacker.currentpossition, defender.currentpossition, mapa, attacker); } //return mapa; }
public void AttackMapEntity(Agent.Creature attacker, OperacjeMapy.Pole[,] mapa, Point defender) { BasicAIDij ai = new BasicAIDij(); Random r = new Random(); int damageDone = r.Next(1, 10); var kill = new KillAgent(defender, mapa, CreaturesToDo.FindEntity.KindOfEntity.mapEntity); bool defenderIsAdjacent; int aPX = attacker.currentpossition.X; int aPY = attacker.currentpossition.Y; int dPX = defender.X; int dPY = defender.Y; if (aPX - 1 == dPX && aPY == dPY) { defenderIsAdjacent = true; } else if (aPX + 1 == dPX && aPY == dPY) { defenderIsAdjacent = true; } else if (aPX == dPX && aPY + 1 == dPY) { defenderIsAdjacent = true; } else if (aPX == dPX && aPY - 1 == dPY) { defenderIsAdjacent = true; } else if (aPX - 1 == dPX && aPY - 1 == dPY) { defenderIsAdjacent = true; } else if (aPX - 1 == dPX && aPY + 1 == dPY) { defenderIsAdjacent = true; } else if (aPX + 1 == dPX && aPY - 1 == dPY) { defenderIsAdjacent = true; } else if (aPX + 1 == dPX && aPY + 1 == dPY) { defenderIsAdjacent = true; } else { defenderIsAdjacent = false; } if (defenderIsAdjacent) { Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent); Console.WriteLine("Hadzia!"); var dmg = Convert.ToByte(r.Next(attacker.weaponsWielded[0].minDamage, attacker.weaponsWielded[0].maxDamage)); mapa[dPX, dPY].mapEntities.HP -= dmg; if (mapa[dPX, dPY].mapEntities.HP <= 0) { kill.Kill(); } } else { Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent); ai.GoTo(attacker.currentpossition, defender, mapa, attacker); } //return mapa; }
public Place() { this.area = new List <Rectangle>(); this.owner = null; }
public void Roam(Agent.Creature creature, OperacjeMapy.Pole[,] mapa) { Random r = new Random(Guid.NewGuid().GetHashCode()); BasicAIDij ai = new BasicAIDij(); //Point whereTo = new Point(); //whereTo = creature.currentpossition; var adjecent = new List <Point>(); adjecent = GetAdjecentPassablePoints(mapa, creature.currentpossition); int randDir = r.Next(0, adjecent.Count); ai.GoTo(creature.currentpossition, adjecent[randDir], mapa, creature); /*switch (randDir){ * case 1: * { * whereTo.X--; * whereTo.Y++; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * case 2: * { * whereTo.Y++; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * case 3: * { * whereTo.X++; * whereTo.Y++; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * case 4: * { * whereTo.X--; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * case 5: * { * * break; * } * case 6: * { * whereTo.X++; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * case 7: * { * whereTo.X--; * whereTo.Y--; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * case 8: * { * * whereTo.Y--; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * case 9: * { * whereTo.X++; * whereTo.Y--; * ai.GoTo(creature.currentpossition, whereTo, mapa, creature); * break; * } * } */ }
public OperacjeMapy.Pole[,] MoveAgent(ConsoleKey keypressed, OperacjeMapy.Pole[,] mapa, Agent.Creature creature, List <Agent.Weapon> weaponList, List <Agent.Creature> creatureList, List <Agent.Resource> resourcesList) { int posX = creature.currentpossition.X; int posY = creature.currentpossition.Y; switch (keypressed) { case ConsoleKey.F1: { var cmd = new CommandLine(); cmd.DrawCommandMenu(weaponList, creatureList, mapa, resourcesList); break; } case ConsoleKey.NumPad8: //Console.WriteLine("Wcisnieto górną strzałkę."); if (creature.currentpossition.Y == 0) { break; } if (mapa[posX, posY - 1].passable) { mapa[posX, posY - 1].Creature.Add(creature); mapa[posX, posY - 1].passable = false; creature.currentpossition = new Point(creature.currentpossition.X, creature.currentpossition.Y - 1); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad2: //Console.WriteLine("Wcisnieto dolną strzałkę."); if (creature.currentpossition.Y == mapa.GetLength(1) - 1) { break; } if (mapa[posX, posY + 1].passable) { mapa[posX, posY + 1].Creature.Add(creature); mapa[posX, posY + 1].passable = false; creature.currentpossition = new Point(creature.currentpossition.X, creature.currentpossition.Y + 1); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad6: //Console.WriteLine("Wcisnieto prawą strzałkę."); if (creature.currentpossition.X == mapa.GetLength(0) - 1) { break; } if (mapa[posX + 1, posY].passable) { mapa[posX + 1, posY].Creature.Add(creature); mapa[posX + 1, posY].passable = false; creature.currentpossition = new Point(creature.currentpossition.X + 1, creature.currentpossition.Y); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad4: //Console.WriteLine("Wcisnieto lewą strzałkę."); if (creature.currentpossition.X == 0) { break; } if (mapa[posX - 1, posY].passable) { mapa[posX - 1, posY].Creature.Add(creature); mapa[posX - 1, posY].passable = false; creature.currentpossition = new Point(creature.currentpossition.X - 1, creature.currentpossition.Y); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad7: //Console.WriteLine("Wcisnieto górną-lewą strzałkę."); if (creature.currentpossition.X == 0 || creature.currentpossition.Y == 0) { break; } if (mapa[posX - 1, posY - 1].passable) { mapa[posX - 1, posY - 1].Creature.Add(creature); mapa[posX - 1, posY - 1].passable = false; creature.currentpossition = new Point(creature.currentpossition.X - 1, creature.currentpossition.Y - 1); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad1: //Console.WriteLine("Wcisnieto dolną-lewą strzałkę."); if (creature.currentpossition.X == 0 || creature.currentpossition.Y == mapa.GetLength(1) - 1) { break; } if (mapa[posX - 1, posY + 1].passable) { mapa[posX - 1, posY + 1].Creature.Add(creature); mapa[posX - 1, posY + 1].passable = false; creature.currentpossition = new Point(creature.currentpossition.X - 1, creature.currentpossition.Y + 1); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad9: //Console.WriteLine("Wcisnieto górną-prawą strzałkę."); if (creature.currentpossition.X == mapa.GetLength(0) - 1 || creature.currentpossition.Y == 0) { break; } if (mapa[posX + 1, posY - 1].passable) { mapa[posX + 1, posY - 1].Creature.Add(creature); mapa[posX + 1, posY - 1].passable = false; creature.currentpossition = new Point(creature.currentpossition.X + 1, creature.currentpossition.Y - 1); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad3: //Console.WriteLine("Wcisnieto dolną-prawą strzałkę."); if (creature.currentpossition.X == mapa.GetLength(0) - 1 || creature.currentpossition.Y == mapa.GetLength(1) - 1) { break; } if (mapa[posX + 1, posY + 1].passable) { mapa[posX + 1, posY + 1].Creature.Add(creature); mapa[posX + 1, posY + 1].passable = false; creature.currentpossition = new Point(creature.currentpossition.X + 1, creature.currentpossition.Y + 1); mapa[posX, posY].Creature.Remove(creature); mapa[posX, posY].passable = true; } break; case ConsoleKey.NumPad5: //Console.WriteLine("Wcisnieto środkową strzałkę."); break; /* * default: * Console.WriteLine("ConsoleKey pressed value is not a strzałka ;("); * break; */ } return(mapa); }
// Spawn creature into coordinates x,y; public void SpawnCreature(Point pos, Agent.Creature creature, OperacjeMapy.Pole[,] mapa) { mapa[pos.X, pos.Y].Creature.Add(creature); mapa[pos.X, pos.Y].passable = false; Console.WriteLine("Spawning {0} to X{1},Y{2}.", creature.name, pos.X, pos.Y); }