public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.Use: Core.UseEventArgs args = (Core.UseEventArgs)e; // position based? if (args.PositionBased) { Core.Entity entityUsing = args.EntityUsing; Components.PositionComp posComp = (Components.PositionComp)_entManager.GetSingleComponentByID(entityUsing.UID, Core.ComponentTypes.Position); int xPos = posComp.X; int yPos = posComp.Y; string posLU = xPos.ToString() + "-" + yPos.ToString(); if (_entManager.EntityPostionLookUp.TryGetValue(posLU, out List <Core.Entity> entry)) { foreach (Core.Entity li in entry) { int useableLU = (int)Core.ComponentTypes.Useable; int stairsLU = (int)Core.ComponentTypes.Stairs; int entBit = _entManager.EntityBitLookUp[li.UID]; if ((useableLU & entBit) > 0) { // is it a stair? if ((entBit & stairsLU) > 0) { // yay! it's a stair.... Components.StairComp stairComp = (Components.StairComp)_entManager.GetSingleComponentByID(li.UID, Core.ComponentTypes.Stairs); if (stairComp.isUp) { // go up } else { //go down } } } } } } else { // non position based, use inventory } break; } }
public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.CollisionCheck: Core.CollisionEventArgs details = (Core.CollisionEventArgs)e; //check entity manager lookup dict //string posKey = details.x.ToString() + "-" + details.y.ToString(); bool collision = false; bool openingDoor = false; List <int> deathList = new List <int>(); //if (_entityManager.EntityPostionLookUp.ContainsKey(posKey)) int entIDRequestingMove = details.EntRequestingMove.UID; HashSet <int> innerIDS = _entityManager.Positions[details.y, details.x]; foreach (int ids in innerIDS) { // we have something there... //List<Core.Entity> entL = _entityManager.EntityPostionLookUp[posKey]; Components.PositionComp pc = (Components.PositionComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Position); if (pc.X == details.x && pc.Y == details.y) { int checker = _entityManager.EntityBitLookUp[ids]; // is it a door? if ((checker & (int)Core.ComponentTypes.Door) > 0) { Components.DoorComp doorComp = (Components.DoorComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Door); if (!doorComp.IsOpen) { openingDoor = true; doorComp.IsOpen = true; _dungeonMap.SetCellProperties(pc.X, pc.Y, true, true); Components.RenderComp rc = (Components.RenderComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Render); rc.Glyph = '-'; } } //is it something living? if ((checker & (int)Core.ComponentTypes.Health) > 0) { //Game.MessageLog.Add("FIGHT NOW"); collision = true; //get details of person being hit Components.HealthComp hComp = (Components.HealthComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Health); Components.AttributesComp attComp = (Components.AttributesComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.Attributes); Components.CreatureDetailsComp detailsComp = (Components.CreatureDetailsComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.CreatureDetails); bool isUndead = detailsComp.Undead; Components.AIComp aiComp = (Components.AIComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.AI); // get hitter details Components.AttributesComp attOfHitterComp = (Components.AttributesComp)_entityManager.GetSingleComponentByID(entIDRequestingMove, Core.ComponentTypes.Attributes); bool hit = false; // base damage = 1 int dmg = 1; int attackSkill = (int)(attComp.Strength + attComp.Dexterity) / 2; if (RogueSharp.DiceNotation.Dice.Roll("1d20") < attackSkill) { hit = true; // get weapon we are using Components.InventoryComp invComp = (Components.InventoryComp)_entityManager.GetSingleComponentByID(entIDRequestingMove, Core.ComponentTypes.Inventory); // get damage bonus int dmgBonus = RogueSharp.DiceNotation.Dice.Roll(attOfHitterComp.DmgBonus); dmgBonus *= attOfHitterComp.DmgMod; if (invComp != null) { if (invComp.CurrentWeapon > 0) { Components.WeaponComp weapon = (Components.WeaponComp)_entityManager.GetSingleComponentByID(invComp.CurrentWeapon, Core.ComponentTypes.Weapon); dmg = RogueSharp.DiceNotation.Dice.Roll(weapon.DamageBase); } } int totalDamage = dmgBonus + dmg; if (totalDamage <= 1) { totalDamage = 1; } hComp.Health -= totalDamage; if (hComp.Health < 0) { hComp.Health = 0; } attComp.Morale -= totalDamage; if (attComp.Morale < 1) { attComp.Morale = 0; } if (hComp.Health < (hComp.MaxHealth * 0.2)) { if (!isUndead) { aiComp.Fleeing = true; } } } aiComp.UnderAttack = true; aiComp.LastBasher = entIDRequestingMove; if (!aiComp.CurrentEnemies.Contains(entIDRequestingMove)) { aiComp.CurrentEnemies.Add(entIDRequestingMove); } Components.CreatureDetailsComp cdComp = (Components.CreatureDetailsComp)_entityManager.GetSingleComponentByID(ids, Core.ComponentTypes.CreatureDetails); List <Components.Component> ourList = _entityManager.GetCompsByID(details.EntRequestingMove.UID); Components.CreatureDetailsComp ourComp = (Components.CreatureDetailsComp)ourList.FirstOrDefault(x => x.CompType == Core.ComponentTypes.CreatureDetails); if (hit) { Game.MessageLog.Add($"{ourComp.PersonalName} Bashes {cdComp.PersonalName} for {dmg} Damage"); } else { Game.MessageLog.Add($"{ourComp.PersonalName} Misses {cdComp.PersonalName}"); } if (hComp.Health < 1) { // entity is dead, collect up and kill at end deathList.Add(ids); } } } } foreach (int i in deathList) { Core.DeleteEntEventArgs msg = new Core.DeleteEntEventArgs(Core.EventTypes.DeadEntity, i); Core.EventBus.Publish(Core.EventTypes.DeadEntity, msg); } if (!collision) { // move okay Core.MoveOkayEventArgs msg = new Core.MoveOkayEventArgs(Core.EventTypes.MoveOK, details.EntRequestingMove, details.x, details.y); Core.EventBus.Publish(Core.EventTypes.MoveOK, msg); } else //if (!openingDoor) { // // fight on Core.NoMoveEventArgs msg = new Core.NoMoveEventArgs(Core.EventTypes.NoMove, details.EntRequestingMove); Core.EventBus.Publish(Core.EventTypes.NoMove, msg); } break; } }
public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.ActionReqMove: // request movement Core.MovementReqEventArgs moveReq = (Core.MovementReqEventArgs)e; Core.Entity entoToMove = moveReq.EntRequestingMove; int eid = entoToMove.UID; Core.Directions dirToMove = moveReq.Direction; Components.PositionComp posComp = (Components.PositionComp)_entityManager.GetSingleComponentByID(eid, Core.ComponentTypes.Position); int newX = posComp.X; int newY = posComp.Y; switch (dirToMove) { case Core.Directions.None: break; case Core.Directions.DownLeft: newX = posComp.X - 1; newY = posComp.Y + 1; break; case Core.Directions.Down: newX = posComp.X; newY = posComp.Y + 1; break; case Core.Directions.DownRight: newX = posComp.X + 1; newY = posComp.Y + 1; break; case Core.Directions.Left: newX = posComp.X - 1; newY = posComp.Y; break; case Core.Directions.Centre: break; case Core.Directions.Right: newX = posComp.X + 1; newY = posComp.Y; break; case Core.Directions.UpLeft: newX = posComp.X - 1; newY = posComp.Y - 1; break; case Core.Directions.Up: newX = posComp.X; newY = posComp.Y - 1; break; case Core.Directions.UpRight: newX = posComp.X + 1; newY = posComp.Y - 1; break; } //check for collision Core.CollisionEventArgs msg = new Core.CollisionEventArgs(Core.EventTypes.CollisionCheck, entoToMove, newX, newY); Core.EventBus.Publish(Core.EventTypes.CollisionCheck, msg); break; case Core.EventTypes.MoveOK: Core.MoveOkayEventArgs m = (Core.MoveOkayEventArgs)e; if (_dungeonMap.GetCell(m.newX, m.newY).IsWalkable) { // get current pos Core.Entity ent = m.EntRequestingMove; Components.PositionComp pos = (Components.PositionComp)_entityManager.GetSingleComponentByID(ent.UID, Core.ComponentTypes.Position); Components.AIComp aiComp = (Components.AIComp)_entityManager.GetSingleComponentByID(ent.UID, Core.ComponentTypes.AI); aiComp.TurnsSinceMove = 0; _dungeonMap.SetIsWalkable(pos.X, pos.Y, true); _entityManager.RemoveEntFromPosition(pos.X, pos.Y, ent.UID); pos.X = m.newX; pos.Y = m.newY; _dungeonMap.SetIsWalkable(m.newX, m.newY, false); _entityManager.AddEntToPosition(m.newX, m.newY, ent.UID); } break; case Core.EventTypes.DirectMove: Core.DirectMoveEventArgs dm = (Core.DirectMoveEventArgs)e; //check for collision Core.CollisionEventArgs checkMsg = new Core.CollisionEventArgs(Core.EventTypes.CollisionCheck, dm.EntRequestingMove, dm.PointToMoveTo.X, dm.PointToMoveTo.Y); Core.EventBus.Publish(Core.EventTypes.CollisionCheck, checkMsg); break; case Core.EventTypes.NoMove: Core.NoMoveEventArgs nmEvent = (Core.NoMoveEventArgs)e; Components.AIComp aiC = (Components.AIComp)_entityManager.GetSingleComponentByID(nmEvent.EntNotMoving.UID, Core.ComponentTypes.AI); if (aiC != null) { aiC.TurnsSinceMove++; } //Game.MessageLog.Add($"Turns Since = {aiC.TurnsSinceMove.ToString()}"); break; } }
public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.InventoryAdd: Core.InventoryAddEventArgs msg = (Core.InventoryAddEventArgs)e; int entPickingUp = msg.EntPickingUp; int pickedUpObj = msg.PickedUpObject; List <Components.Component> pickedUpObjComps = _entityManager.GetCompsByID(pickedUpObj); List <Components.Component> entComps = _entityManager.GetCompsByID(entPickingUp); Components.InventoryComp invComp = (Components.InventoryComp)_entityManager.GetSingleComponentByID(entPickingUp, Core.ComponentTypes.Inventory); if (invComp != null) { Components.PositionComp posComp = (Components.PositionComp)pickedUpObjComps.Find(x => x.CompType == Core.ComponentTypes.Position); Components.CollectableComp collectComp = (Components.CollectableComp)pickedUpObjComps.Find(x => x.CompType == Core.ComponentTypes.Collectable); Components.ItemValueComp vC = (Components.ItemValueComp)pickedUpObjComps.Find(x => x.CompType == Core.ComponentTypes.ItemValue); //Components.Component c = _entityManager.GetSingleComponentByID(collectComp.) bool hasValue = (vC != null); if (collectComp.Active) { //is it treasure? if (collectComp.Treasure) { //TODO stackable treasure if (vC != null) { invComp.ValueCarried += vC.ItemValue; } // remove position comps from picked up object _entityManager.RemoveCompFromEnt(pickedUpObj, Core.ComponentTypes.Position); collectComp.Active = false; _entityManager.RemoveEntFromPosition(posComp.X, posComp.Y, pickedUpObj); invComp.Treasure.Add(pickedUpObj); } else { // is it stackable? - not currently used //TODO stackable collectables if (collectComp.Stackable) { } else { Game.MessageLog.Add("picking up item"); // System.Threading.Thread.Sleep(1000); if (posComp != null) { _entityManager.RemoveEntFromPosition(posComp.X, posComp.Y, pickedUpObj); _entityManager.RemoveCompFromEnt(pickedUpObj, Core.ComponentTypes.Position); pickedUpObjComps.Remove(posComp); } invComp.Inventory.Add(pickedUpObj); } } } } break; } }
public void OnMessage(Core.MessageEventArgs e) { switch (e.MessageType) { case Core.EventTypes.DeleteEntity: Core.DeleteEntEventArgs msg = (Core.DeleteEntEventArgs)e; //_entsToDelete.Add(msg.entID); // set cell walkable List <Components.Component> compList = _entityManager.GetCompsByID(msg.entID); Components.PositionComp pc = (Components.PositionComp)compList.FirstOrDefault(x => x.CompType == Core.ComponentTypes.Position); _dungeonMap.SetIsWalkable(pc.X, pc.Y, true); _shedSystem.Remove(_entityManager.JustEntities[msg.entID]); _entityManager.RemoveEntity(msg.entID); break; case Core.EventTypes.DeadEntity: // leave corpse of entity Core.DeleteEntEventArgs dM = (Core.DeleteEntEventArgs)e; int entID = dM.entID; Components.PositionComp posC = (Components.PositionComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Position); _dungeonMap.SetIsWalkable(posC.X, posC.Y, true); Components.RenderComp rendC = (Components.RenderComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Render); rendC.Glyph = '%'; rendC.Colour = RLNET.RLColor.LightRed; Components.AttributesComp attC = (Components.AttributesComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Attributes); attC.Dead = true; Game.MessageLog.Add($"ENT IS DEAD YEAH: {attC.Dead} ----------------------------------------------------------------------------"); _shedSystem.Remove(_entityManager.JustEntities[entID]); _entityManager.RemoveCompFromEnt(entID, Core.ComponentTypes.Health); _entityManager.RemoveCompFromEnt(entID, Core.ComponentTypes.Actor); _entityManager.RemoveCompFromEnt(entID, Core.ComponentTypes.Schedulable); _entityManager.AddFurnitureToEnt(entID); _entityManager.AddDeadComp(entID); // drop inventory Components.InventoryComp invC = (Components.InventoryComp)_entityManager.GetSingleComponentByID(entID, Core.ComponentTypes.Inventory); if (invC != null) { foreach (int droppedID in invC.Inventory) { Components.CollectableComp cc = (Components.CollectableComp)_entityManager.GetSingleComponentByID(droppedID, Core.ComponentTypes.Collectable); // only drop treasure for the moment //TODO - drop other items apart from treasure if (cc.Treasure) { _entityManager.AddPositionToEnt(droppedID, posC.X, posC.Y); cc.Active = true; } } } break; } }