예제 #1
0
        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;
            }
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        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;
            }
        }