Exemple #1
0
        public override ReturnTypes QueryAdd(int index, Thing thing, uint count, CylinderFlags cFlags, Creature actor = null)
        {
            Item item = thing as Item;

            if (item == null)
            {
                return(ReturnTypes.NotPossible);
            }

            bool skipLimit = cFlags.HasFlag(CylinderFlags.Nolimit);

            if (!skipLimit)
            {
                int addCount = 0;

                if ((item.IsStackable && item.Count != count))
                {
                    addCount = 1;
                }

                if (item.GetTopParent() != this)
                {
                    Container container = item as Container;
                    if (container != null)
                    {
                        addCount = container.ItemList.Count + 1;
                    }
                    else
                    {
                        addCount = 1;
                    }
                }

                if (ItemList.Count + addCount > MaxDepotItems)
                {
                    return(ReturnTypes.DepotIsFull);
                }
            }

            return(base.QueryAdd(index, thing, count, cFlags, actor));
        }
Exemple #2
0
        public override Thing QueryDestination(ref int index, Thing thing, ref Item destItem, ref CylinderFlags flags)
        {
            Tile destTile = null;

            destItem = null;

            if (Flags.HasFlag(TileFlags.FloorChangeDown))
            {
                ushort dx = Position.X;
                ushort dy = Position.Y;
                byte   dz = (byte)(Position.Z + 1);

                Tile southDownTile = Map.GetTile(dx, (ushort)(dy - 1), dz);
                if (southDownTile != null && southDownTile.FloorChange(Directions.SouthAlt))
                {
                    dy      -= 2;
                    destTile = Map.GetTile(dx, dy, dz);
                }
                else
                {
                    Tile eastDownTile = Map.GetTile((ushort)(dx - 1), dy, dz);
                    if (eastDownTile != null && eastDownTile.FloorChange(Directions.EastAlt))
                    {
                        dx      -= 2;
                        destTile = Map.GetTile(dx, dy, dz);
                    }
                    else
                    {
                        Tile downTile = Map.GetTile(dx, dy, dz);
                        if (downTile != null)
                        {
                            if (downTile.FloorChange(Directions.North))
                            {
                                ++dy;
                            }

                            if (downTile.FloorChange(Directions.South))
                            {
                                --dy;
                            }

                            if (downTile.FloorChange(Directions.SouthAlt))
                            {
                                dy -= 2;
                            }

                            if (downTile.FloorChange(Directions.East))
                            {
                                --dx;
                            }

                            if (downTile.FloorChange(Directions.EastAlt))
                            {
                                dx -= 2;
                            }

                            if (downTile.FloorChange(Directions.West))
                            {
                                ++dx;
                            }

                            destTile = Map.GetTile(dx, dy, dz);
                        }
                    }
                }
            }
            else if (Flags.HasFlag(TileFlags.FloorChange))
            {
                ushort dx = Position.X;
                ushort dy = Position.Y;
                byte   dz = (byte)(Position.Z - 1);

                if (FloorChange(Directions.North))
                {
                    --dy;
                }

                if (FloorChange(Directions.South))
                {
                    ++dy;
                }

                if (FloorChange(Directions.East))
                {
                    ++dx;
                }

                if (FloorChange(Directions.West))
                {
                    --dx;
                }

                if (FloorChange(Directions.SouthAlt))
                {
                    dy += 2;
                }

                if (FloorChange(Directions.EastAlt))
                {
                    dx += 2;
                }

                destTile = Map.GetTile(dx, dy, dz);
            }

            if (destTile == null)
            {
                destTile = this;
            }
            else
            {
                flags |= CylinderFlags.Nolimit;    //Will ignore that there is blocking items/creatures
            }

            Thing destThing = destTile.GetTopDownItem();

            if (destThing != null)
            {
                destItem = destThing as Item;
            }

            return(destTile);
        }
Exemple #3
0
        public override ReturnTypes QueryAdd(int index, Thing thing, uint count, CylinderFlags cFlags, Creature actor = null)
        {
            Item     item;
            Creature creature;

            if ((creature = thing as Creature) != null)
            {
                if (cFlags.HasFlag(CylinderFlags.Nolimit))
                {
                    return(ReturnTypes.NoError);
                }

                if (cFlags.HasFlag(CylinderFlags.Pathfinding))
                {
                    if (Flags.HasFlag(TileFlags.FloorChange) || Flags.HasFlag(TileFlags.Teleport))
                    {
                        return(ReturnTypes.NotPossible);
                    }
                }

                if (Ground == null)
                {
                    return(ReturnTypes.NotPossible);
                }

                Monster monster = creature as Monster;
                if (monster != null)
                {
                    if (Flags.HasFlag(TileFlags.ProtectionZone))
                    {
                        return(ReturnTypes.NotPossible);
                    }

                    if (Flags.HasFlag(TileFlags.FloorChange) || Flags.HasFlag(TileFlags.Teleport))
                    {
                        return(ReturnTypes.NotPossible);
                    }

                    //TODO: After monsters
                    //const CreatureVector* creatures = getCreatures();
                    //if (monster->canPushCreatures() && !monster->isSummon()) {
                    //    if (creatures) {
                    //        for (Creature* tileCreature : *creatures) {
                    //            if (tileCreature->getPlayer() && tileCreature->getPlayer()->isInGhostMode()) {
                    //                continue;
                    //            }

                    //            const Monster* creatureMonster = tileCreature->getMonster();
                    //            if (!creatureMonster || !tileCreature->isPushable() ||
                    //                    (creatureMonster->isSummon() && creatureMonster->getMaster()->getPlayer())) {
                    //                return RETURNVALUE_NOTPOSSIBLE;
                    //            }
                    //        }
                    //    }
                    //} else if (creatures && !creatures->empty()) {
                    //    for (const Creature* tileCreature : *creatures) {
                    //        if (!tileCreature->isInGhostMode()) {
                    //            return RETURNVALUE_NOTENOUGHROOM;
                    //        }
                    //    }
                    //}

                    //if (hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID)) {
                    //    return RETURNVALUE_NOTPOSSIBLE;
                    //}

                    //if (hasBitSet(FLAG_PATHFINDING, flags) && hasFlag(TILESTATE_IMMOVABLENOFIELDBLOCKPATH)) {
                    //    return RETURNVALUE_NOTPOSSIBLE;
                    //}

                    //if (hasFlag(TILESTATE_BLOCKSOLID) || (hasBitSet(FLAG_PATHFINDING, flags) && hasFlag(TILESTATE_NOFIELDBLOCKPATH))) {
                    //    if (!(monster->canPushItems() || hasBitSet(FLAG_IGNOREBLOCKITEM, flags))) {
                    //        return RETURNVALUE_NOTPOSSIBLE;
                    //    }
                    //}

                    //MagicField* field = getFieldItem();
                    //if (field && !field->isBlocking()) {
                    //    CombatType_t combatType = field->getCombatType();

                    //    //There is 3 options for a monster to enter a magic field
                    //    //1) Monster is immune
                    //    if (!monster->isImmune(combatType)) {
                    //        //1) Monster is "strong" enough to handle the damage
                    //        //2) Monster is already afflicated by this type of condition
                    //        if (hasBitSet(FLAG_IGNOREFIELDDAMAGE, flags)) {
                    //            if (!(monster->canPushItems() || monster->hasCondition(Combat::DamageToConditionType(combatType)))) {
                    //                return RETURNVALUE_NOTPOSSIBLE;
                    //            }
                    //        } else {
                    //            return RETURNVALUE_NOTPOSSIBLE;
                    //        }
                    //    }
                    //}

                    //return RETURNVALUE_NOERROR;
                }

                Player player = creature as Player;
                if (player != null)
                {
                    if (Creatures != null && Creatures.Count != 0 && !cFlags.HasFlag(CylinderFlags.IgnoreBlockCreature) && !player.Group.Access)
                    {
                        foreach (Creature tileCreature in Creatures)
                        {
                            if (!player.CanWalkthrough(tileCreature))
                            {
                                return(ReturnTypes.NotPossible);
                            }
                        }
                    }

                    if (player.Parent == null && Flags.HasFlag(TileFlags.NoLogout))
                    {
                        return(ReturnTypes.NotPossible); //player is trying to login to a "no logout" tile
                    }
                    Tile playerTile = player.Parent;
                    if (playerTile != null && player.IsPzLocked)
                    {
                        if (!playerTile.Flags.HasFlag(TileFlags.PvpZone))
                        {
                            //player is trying to enter a pvp zone while being pz-locked
                            if (Flags.HasFlag(TileFlags.PvpZone))
                            {
                                return(ReturnTypes.PlayerIsPZLockedEnterPvpZone);
                            }
                        }
                        else if (!Flags.HasFlag(TileFlags.PvpZone))
                        {
                            // player is trying to leave a pvp zone while being pz-locked
                            return(ReturnTypes.PlayerIsPZLockedLeavePvpZone);
                        }

                        if ((!playerTile.Flags.HasFlag(TileFlags.NoPvpZone) && Flags.HasFlag(TileFlags.NoPvpZone)) ||
                            (!playerTile.Flags.HasFlag(TileFlags.ProtectionZone) && Flags.HasFlag(TileFlags.ProtectionZone)))
                        {
                            // player is trying to enter a non-pvp/protection zone while being pz-locked
                            return(ReturnTypes.PlayerIsPZLocked);
                        }
                    }
                }
                else if (Creatures != null && Creatures.Count != 0 && cFlags.HasFlag(CylinderFlags.IgnoreBlockCreature))
                {
                    foreach (Creature tileCreature in Creatures)
                    {
                        if (!tileCreature.IsInGhostMode())
                        {
                            return(ReturnTypes.NotEnoughRoom);
                        }
                    }
                }

                if (!cFlags.HasFlag(CylinderFlags.IgnoreBlockItem))
                {
                    //If the CylinderFlags.IgnoreBlockItem bit isn't set we dont have to iterate every single item
                    if (Flags.HasFlag(TileFlags.BlockSolid))
                    {
                        return(ReturnTypes.NotEnoughRoom);
                    }
                }
                else
                {
                    //CylinderFlags.IgnoreBlockItem is set
                    if (Ground != null)
                    {
                        ItemTemplate it = ItemManager.Templates[Ground.Id];
                        if (it.DoesBlockSolid && (!it.IsMoveable))// || Ground->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID))) { TODO: Attributes
                        {
                            return(ReturnTypes.NotPossible);
                        }
                    }

                    if (Items != null)
                    {
                        foreach (Item stackItem in Items)
                        {
                            ItemTemplate it = ItemManager.Templates[stackItem.Id];
                            if (it.DoesBlockSolid && (!it.IsMoveable))// || item->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID))) {
                            {
                                return(ReturnTypes.NotPossible);
                            }
                        }
                    }
                }
            }
            else if ((item = thing as Item) != null)
            {
                if (Items != null && Items.Count >= 0xFFFF)
                {
                    return(ReturnTypes.NotPossible);
                }

                if (cFlags.HasFlag(CylinderFlags.Nolimit))
                {
                    return(ReturnTypes.NoError);
                }

                bool itemIsHangable = item.IsHangable;
                if (Ground == null && !itemIsHangable)
                {
                    return(ReturnTypes.NotPossible);
                }

                if (Creatures != null && Creatures.Count != 0 && item.IsBlocking && !cFlags.HasFlag(CylinderFlags.IgnoreBlockCreature))
                {
                    foreach (Creature tileCreature in Creatures)
                    {
                        if (!tileCreature.IsInGhostMode())
                        {
                            return(ReturnTypes.NotEnoughRoom);
                        }
                    }
                }

                if (itemIsHangable && Flags.HasFlag(TileFlags.SupportsHangable))
                {
                    if (Items != null)
                    {
                        foreach (Item tileItem in Items)
                        {
                            if (tileItem.IsHangable)
                            {
                                return(ReturnTypes.NeedExchange);
                            }
                        }
                    }
                }
                else
                {
                    if (Ground != null)
                    {
                        ItemTemplate itemTemplate = ItemManager.Templates[Ground.Id];
                        if (itemTemplate.DoesBlockSolid)
                        {
                            if (!itemTemplate.DoesAllowPickupable || item.IsMagicField || item.IsBlocking)
                            {
                                if (!item.IsPickupable)
                                {
                                    return(ReturnTypes.NotEnoughRoom);
                                }

                                if (!itemTemplate.HasHeight || itemTemplate.IsPickupable || itemTemplate.Type == ItemTypes.Bed)
                                {
                                    return(ReturnTypes.NotEnoughRoom);
                                }
                            }
                        }
                    }

                    if (Items != null)
                    {
                        foreach (Item tileItem in Items)
                        {
                            ItemTemplate itemTemplate = ItemManager.Templates[tileItem.Id];

                            if (!itemTemplate.DoesBlockSolid)
                            {
                                continue;
                            }

                            if (itemTemplate.DoesAllowPickupable && !item.IsMagicField && !item.IsBlocking)
                            {
                                continue;
                            }

                            if (!item.IsPickupable)
                            {
                                return(ReturnTypes.NotEnoughRoom);
                            }

                            if (!itemTemplate.HasHeight || itemTemplate.IsPickupable || itemTemplate.Type == ItemTypes.Bed)
                            {
                                return(ReturnTypes.NotEnoughRoom);
                            }
                        }
                    }
                }
            }

            return(ReturnTypes.NoError);
        }
Exemple #4
0
 public virtual Thing QueryDestination(ref int index, Thing thing, ref Item destItem, ref CylinderFlags flags)
 {
     return(null);
 }
Exemple #5
0
 public virtual ReturnTypes QueryRemove(Thing thing, uint count, CylinderFlags flags)
 {
     return(ReturnTypes.NoError);
 }
Exemple #6
0
 public virtual ReturnTypes QueryMaxCount(int index, Thing thing, uint count, ref uint maxQueryCount, CylinderFlags flags)
 {
     return(ReturnTypes.NoError);
 }
Exemple #7
0
 //Cylinder is implemented as Thing as well!
 public virtual ReturnTypes QueryAdd(int index, Thing thing, uint count, CylinderFlags cFlags, Creature actor = null)
 {
     return(ReturnTypes.NoError);
 }