Exemple #1
0
        public static void do_fill(CharacterInstance ch, string argument)
        {
            var firstArg = argument.FirstWord();

            if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "Fill what?"))
            {
                return;
            }
            if (handler.FindObject_CheckMentalState(ch))
            {
                return;
            }

            var obj = ch.GetCarriedObject(firstArg);

            if (CheckFunctions.CheckIfNullObject(ch, obj, "You do not have that item."))
            {
                return;
            }

            if (obj.ItemType == ItemTypes.Container)
            {
                if (obj.Values.Flags.IsSet(ContainerFlags.Closed))
                {
                    comm.act(ATTypes.AT_PLAIN, "The $d is closed.", ch, null, obj.Name, ToTypes.Character);
                    return;
                }
                if (CheckFunctions.CheckIfTrue(ch, obj.GetRealWeight() / obj.Count >= obj.Values.Capacity,
                                               "It's already full as it can be."))
                {
                    return;
                }
            }
            else
            {
                if (CheckFunctions.CheckIfTrue(ch,
                                               (GetMaximumCondition() < 1) || (obj.Values.Quantity >= obj.Values.Capacity),
                                               "It's already full as it can be."))
                {
                    return;
                }
            }

            if (CheckFunctions.CheckIfTrue(ch,
                                           obj.ItemType == ItemTypes.Pipe && obj.Values.Flags.IsSet(PipeFlags.FullOfAsh),
                                           "It's full of ashes, and needs to be emptied first."))
            {
                return;
            }

            var sourceItemTypes = ChooseSourceItemTypes(ch, obj);

            var secondArg = argument.SecondWord();

            if (secondArg.EqualsIgnoreCase("from") ||
                secondArg.EqualsIgnoreCase("with"))
            {
                secondArg = argument.ThirdWord();
            }

            ObjectInstance source = null;
            var            all    = false;

            if (!secondArg.IsNullOrEmpty())
            {
                handler.separate_obj(obj);

                if (obj.ItemType == ItemTypes.Container &&
                    (secondArg.EqualsIgnoreCase("all") || secondArg.StartsWithIgnoreCase("all.")))
                {
                    all = true;
                }
                else if (obj.ItemType == ItemTypes.Pipe)
                {
                    source = ch.GetCarriedObject(secondArg);
                    if (CheckFunctions.CheckIfNullObject(ch, source, "You don't have that item."))
                    {
                        return;
                    }
                    if (sourceItemTypes.All(x => x != source.ItemType))
                    {
                        comm.act(ATTypes.AT_PLAIN, "You cannot fill $p with $P!", ch, obj, source, ToTypes.Character);
                        return;
                    }
                }
                else
                {
                    source = ch.GetObjectOnMeOrInRoom(secondArg);
                    if (CheckFunctions.CheckIfNullObject(ch, source, "You cannot find that item."))
                    {
                        return;
                    }
                }
            }
            else
            {
                source = null;
            }

            if (CheckFunctions.CheckIfTrue(ch, source == null && obj.ItemType == ItemTypes.Pipe,
                                           "Fill it with what?"))
            {
                return;
            }

            bool found = false;

            if (source != null)
            {
                foreach (var sourceObj in ch.CurrentRoom.Contents)
                {
                    source = sourceObj;
                    if (obj.ItemType == ItemTypes.Container)
                    {
                        if (ch.CanWear(source, ItemWearFlags.Take) || source.IsObjStat(ItemExtraFlags.Buried) ||
                            (source.IsObjStat(ItemExtraFlags.Prototype) && ch.CanTakePrototype()) ||
                            ch.CarryWeight + source.GetWeight() > ch.CanCarryMaxWeight() ||
                            (source.GetRealWeight() + obj.GetRealWeight() / obj.Count) > obj.Value[0])
                        {
                            continue;
                        }

                        if (all && secondArg[3] == '.' && secondArg.Substring(4).IsAnyEqual(source.Name))
                        {
                            continue;
                        }

                        source.InRoom.Contents.Remove(source);
                        if (source.ItemType == ItemTypes.Money)
                        {
                            ch.CurrentCoin += source.Value[0];
                            source.Extract();
                        }
                        else
                        {
                            source.AddTo(obj);
                        }
                        found = true;
                    }
                    else if (sourceItemTypes.Any(x => x == source.ItemType))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    if (SourceItemTypeNotFoundTable.TryGetValue(sourceItemTypes.First(), out var message))
                    {
                        ch.SendTo(message);
                    }
                    else
                    {
                        ch.SendTo("There is nothing appropriate here!");
                    }
                }

                if (obj.ItemType == ItemTypes.Container)
                {
                    comm.act(ATTypes.AT_ACTION, "You fill $p.", ch, obj, null, ToTypes.Character);
                    comm.act(ATTypes.AT_ACTION, "$n fills $p.", ch, obj, null, ToTypes.Room);
                    return;
                }
            }

            if (obj.ItemType == ItemTypes.Container)
            {
                if (source == obj)
                {
                    ch.SendTo("You can't fill something with itself!");
                    return;
                }

                switch (source.ItemType)
                {
                case ItemTypes.Money:
                    ch.SendTo("You can't do that... yet.");
                    break;

                case ItemTypes.PlayerCorpse:
                    if (ch.IsNpc())
                    {
                        ch.SendTo("You can't do that.");
                        return;
                    }

                    if (source.IsObjStat(ItemExtraFlags.ClanCorpse) && !ch.IsImmortal())
                    {
                        ch.SendTo("Your hands fumble.  Maybe you better loot a different way.");
                        return;
                    }

                    if (!source.IsObjStat(ItemExtraFlags.ClanCorpse) || !((PlayerInstance)ch).PlayerData.Flags.IsSet((int)PCFlags.Deadly))
                    {
                        // TODO liquids.c lines 1734 to 1758
                    }
                    break;

                case ItemTypes.Container:
                    if (source.ItemType == ItemTypes.Container && source.Value[1].IsSet((int)ContainerFlags.Closed))
                    {
                        comm.act(ATTypes.AT_PLAIN, "The $d is closed.", ch, null, source.Name, ToTypes.Character);
                        return;
                    }
                    break;

                case ItemTypes.NpcCorpse:
                    if (!source.Contents.Any())
                    {
                        ch.SendTo("It's empty.");
                        return;
                    }

                    handler.separate_obj(obj);

                    bool wasFound = false;
                    foreach (var contentObj in source.Contents)
                    {
                        if (!ch.CanWear(contentObj, ItemWearFlags.Take) ||
                            (contentObj.IsObjStat(ItemExtraFlags.Prototype) && !ch.CanTakePrototype()) ||
                            ch.CarryNumber + contentObj.Count > ch.CanCarryN() ||
                            ch.CarryWeight + contentObj.GetWeight() > ch.CanCarryMaxWeight() ||
                            (source.GetRealWeight() + obj.GetRealWeight() / obj.Count) > obj.Value[0])
                        {
                            continue;
                        }

                        contentObj.RemoveFrom(source);
                        contentObj.AddTo(obj);
                        wasFound = true;
                    }

                    if (wasFound)
                    {
                        comm.act(ATTypes.AT_ACTION, "You fill $p from $P.", ch, obj, source, ToTypes.Character);
                        comm.act(ATTypes.AT_ACTION, "$n fills $p from $P.", ch, obj, source, ToTypes.Room);
                    }
                    else
                    {
                        ch.SendTo("There is nothing appropriate in there.");
                    }
                    break;

                default:
                    if (source.InRoom == null ||
                        ch.CanWear(source, ItemWearFlags.Take) ||
                        (obj.IsObjStat(ItemExtraFlags.Prototype) && !ch.CanTakePrototype()) ||
                        ch.CarryWeight + source.GetWeight() > ch.CanCarryMaxWeight() ||
                        (source.GetRealWeight() + obj.GetRealWeight() / obj.Count) > obj.Value[0])
                    {
                        ch.SendTo("You can't do that.");
                        return;
                    }

                    handler.separate_obj(obj);
                    comm.act(ATTypes.AT_ACTION, "You take $P and put it inside $p.", ch, obj, source, ToTypes.Character);
                    comm.act(ATTypes.AT_ACTION, "$n takes $P and puts it inside $p.", ch, obj, source, ToTypes.Room);
                    source.InRoom.Contents.Remove(source);
                    source.AddTo(obj);
                    break;
                }
                return;
            }

            if (source.Value[1] < 1)
            {
                ch.SendTo("There's none left!");
                return;
            }

            if (source.Count > 1 && source.ItemType != ItemTypes.Fountain)
            {
                handler.separate_obj(source);
            }
            handler.separate_obj(obj);

            var diff = GetMaximumCondition();

            switch (obj.ItemType)
            {
            case ItemTypes.Fountain:
                if (obj.Value[1] != 0 && obj.Value[2] != 0)
                {
                    ch.SendTo("There is already another liquid in it.");
                    return;
                }

                obj.Value[2] = 0;
                obj.Value[1] = obj.Value[0];
                comm.act(ATTypes.AT_ACTION, "You fill $p from $P.", ch, obj, source, ToTypes.Character);
                comm.act(ATTypes.AT_ACTION, "$n fills $p from $P.", ch, obj, source, ToTypes.Room);
                return;

            case ItemTypes.Blood:
                if (obj.Value[1] != 0 && obj.Value[2] != 13)
                {
                    ch.SendTo("There is already another liquid in it.");
                    return;
                }

                obj.Value[2] = 13;
                if (source.Value[1] < diff)
                {
                    diff = source.Value[1];
                }

                obj.Value[1] += diff;
                comm.act(ATTypes.AT_ACTION, "You fill $p from $p.", ch, obj, source, ToTypes.Character);
                comm.act(ATTypes.AT_ACTION, "$n fills $p from $P.", ch, obj, source, ToTypes.Room);

                source.Value[1] -= diff;
                if (source.Value[1] < 1)
                {
                    source.Extract();
                    ObjectFactory.CreateBloodstain(ch);
                }
                return;

            case ItemTypes.Herb:
                if (obj.Value[1] != 0 && obj.Value[2] != source.Value[2])
                {
                    ch.SendTo("There is already another type of herb in it.");
                    return;
                }

                obj.Value[2] = source.Value[2];
                if (source.Value[1] < diff)
                {
                    diff = source.Value[1];
                }

                obj.Value[1] += diff;
                comm.act(ATTypes.AT_ACTION, "You fill $p from $p.", ch, obj, source, ToTypes.Character);
                comm.act(ATTypes.AT_ACTION, "$n fills $p from $P.", ch, obj, source, ToTypes.Room);

                source.Value[1] -= diff;
                if (source.Value[1] < 1)
                {
                    source.Extract();
                }
                return;

            case ItemTypes.HerbContainer:
                if (obj.Value[1] != 0 && obj.Value[2] != source.Value[2])
                {
                    ch.SendTo("There is already another type of herb in it.");
                    return;
                }

                obj.Value[2] = source.Value[2];
                if (source.Value[1] < diff)
                {
                    diff = source.Value[1];
                }

                obj.Value[1] += diff;
                comm.act(ATTypes.AT_ACTION, "You fill $p from $p.", ch, obj, source, ToTypes.Character);
                comm.act(ATTypes.AT_ACTION, "$n fills $p from $P.", ch, obj, source, ToTypes.Room);
                return;

            case ItemTypes.DrinkContainer:
                if (obj.Value[1] != 0 && obj.Value[2] != source.Value[2])
                {
                    ch.SendTo("There is already another liquid in it.");
                    return;
                }

                obj.Value[2] = source.Value[2];
                if (source.Value[1] < diff)
                {
                    diff = source.Value[1];
                }

                obj.Value[1]    += diff;
                source.Value[1] -= diff;

                comm.act(ATTypes.AT_ACTION, "You fill $p from $P.", ch, obj, source, ToTypes.Character);
                comm.act(ATTypes.AT_ACTION, "$n fills $p from $P.", ch, obj, source, ToTypes.Room);
                return;

            default:
                // TODO bug
                ch.SendTo("Somethign went wrong...");
                return;
            }
        }
Exemple #2
0
        public static void get_obj(CharacterInstance ch, ObjectInstance obj, ObjectInstance container)
        {
            if (CheckFunctions.CheckIfTrue(ch, !obj.WearFlags.IsSet(ItemWearFlags.Take) &&
                                           (ch.Level < GameManager.Instance.SystemData.GetMinimumLevel(PlayerPermissionTypes.LevelGetObjectNoTake)),
                                           "You can't take that."))
            {
                return;
            }

            if (obj.MagicFlags.IsSet(ItemMagicFlags.PKDisarmed) && !ch.IsNpc())
            {
                var timer = ch.GetTimer(TimerTypes.PKilled);
                if (ch.CanPKill() && timer == null)
                {
                    if (ch.Level - obj.Value.ToList()[5] > 5 || obj.Value.ToList()[5] - ch.Level > 5)
                    {
                        ch.SendTo("\r\n&bA godly force freezes your outstretched hand.");
                        return;
                    }

                    obj.MagicFlags.RemoveBit(ItemMagicFlags.PKDisarmed);
                    obj.Value.ToList()[5] = 0;
                }
            }
            else
            {
                ch.SendTo("\r\n&BA godly force freezes your outstretched hand.");
                return;
            }

            if (CheckFunctions.CheckIfTrue(ch, obj.ExtraFlags.IsSet((int)ItemExtraFlags.Prototype) && !ch.CanTakePrototype(),
                                           "A godly force prevents you from getting close to it."))
            {
                return;
            }

            if (ch.CarryNumber + obj.ObjectNumber > ch.CanCarryN())
            {
                comm.act(ATTypes.AT_PLAIN, "$d: you can't carry that many items.", ch, null, obj.ShortDescription, ToTypes.Character);
                return;
            }

            var weight = obj.ExtraFlags.IsSet((int)ItemExtraFlags.Covering)
                             ? obj.Weight
                             : obj.GetWeight();

            if (obj.ItemType != ItemTypes.Money)
            {
                if (obj.InObject != null)
                {
                    var tObject     = obj.InObject;
                    var inobj       = 1;
                    var checkweight = tObject.ItemType == ItemTypes.Container &&
                                      tObject.ExtraFlags.IsSet((int)ItemExtraFlags.Magical);

                    while (tObject.InObject != null)
                    {
                        tObject = tObject.InObject;
                        inobj++;

                        checkweight = tObject.ItemType == ItemTypes.Container &&
                                      tObject.ExtraFlags.IsSet((int)ItemExtraFlags.Magical);
                    }

                    if (tObject.CarriedBy == null || tObject.CarriedBy != ch || checkweight)
                    {
                        if (ch.CarryWeight + weight > ch.CanCarryMaxWeight())
                        {
                            comm.act(ATTypes.AT_PLAIN, "$d: you can't carry that much weight.", ch, null, obj.ShortDescription, ToTypes.Character);
                            return;
                        }
                    }
                }
                else if (ch.CarryWeight + weight > ch.CanCarryMaxWeight())
                {
                    comm.act(ATTypes.AT_PLAIN, "$d: you can't carry that much weight.", ch, null, obj.ShortDescription, ToTypes.Character);
                    return;
                }
            }

            if (container != null)
            {
                GetObjectFromContainer(ch, obj, container);
            }
            else
            {
                GetObjectFromRoom(ch, obj);
            }

            if (ch.CurrentRoom.Flags.IsSet(RoomFlags.ClanStoreroom) &&
                (container?.CarriedBy == null))
            {
                foreach (var clan in RepositoryManager.Instance.CLANS.Values)
                {
                    if (clan.StoreRoom == ch.CurrentRoom.ID)
                    {
                        save_clan_storeroom(ch, clan);
                    }
                }
            }

            if (obj.ItemType != ItemTypes.Container)
            {
                ch.CheckObjectForTrap(obj, TrapTriggerTypes.Get);
            }
            if (ch.CharDied())
            {
                return;
            }

            if (obj.ItemType == ItemTypes.Money)
            {
                int amt = obj.Values.NumberOfCoins * obj.Count;
                ch.CurrentCoin += amt;
                obj.Extract();
            }
            else
            {
                obj = obj.AddTo(ch);
            }

            if (ch.CharDied() || handler.obj_extracted(obj))
            {
                return;
            }

            MudProgHandler.ExecuteObjectProg(MudProgTypes.Get, ch, obj);
        }
Exemple #3
0
        public static void do_bury(CharacterInstance ch, string argument)
        {
            var firstArg = argument.FirstWord();

            if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "What do you wish to bury?"))
            {
                return;
            }
            if (handler.FindObject_CheckMentalState(ch))
            {
                return;
            }

            var shovel = ch.Carrying.FirstOrDefault(x => x.ItemType == ItemTypes.Shovel);
            var obj    = ch.GetObjectOnMeOrInRoom(firstArg);

            if (CheckFunctions.CheckIfNullObject(ch, obj, "You can't find it."))
            {
                return;
            }

            obj.Split();
            if (!obj.WearFlags.IsSet(ItemWearFlags.Take))
            {
                if (!obj.ExtraFlags.IsSet((int)ItemExtraFlags.ClanCorpse) || ch.IsNpc() ||
                    !((PlayerInstance)ch).PlayerData.Flags.IsSet(PCFlags.Deadly))
                {
                    comm.act(ATTypes.AT_PLAIN, "You cannot bury $p.", ch, obj, null, ToTypes.Character);
                    return;
                }
            }

            var sectorType = ch.CurrentRoom.SectorType;

            if (CheckFunctions.CheckIfTrue(ch, sectorType == SectorTypes.City || sectorType == SectorTypes.Inside,
                                           "The floor is too hard to dig through."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch,
                                           sectorType == SectorTypes.DeepWater || sectorType == SectorTypes.ShallowWater ||
                                           sectorType == SectorTypes.Underwater, "you cannot bury something here."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, sectorType == SectorTypes.Air, "What?  In the air?!"))
            {
                return;
            }

            var carryWeight = 5.GetHighestOfTwoNumbers(ch.CanCarryMaxWeight() / 10);

            if (CheckFunctions.CheckIfTrue(ch, shovel == null && obj.GetWeight() > carryWeight,
                                           "You'd need a shovel to bury something that big."))
            {
                return;
            }

            var move = obj.GetWeight() * 50 * (shovel != null ? 1 : 5) /
                       1.GetHighestOfTwoNumbers(ch.CanCarryMaxWeight());

            move = 2.GetNumberThatIsBetween(move, 1000);
            if (CheckFunctions.CheckIfTrue(ch, move > ch.CurrentMovement,
                                           "You don't have the energy to bury something of that size."))
            {
                return;
            }

            ch.CurrentMovement -= move;
            if (obj.ItemType == ItemTypes.NpcCorpse || obj.ItemType == ItemTypes.PlayerCorpse)
            {
                ((PlayerInstance)ch).AdjustFavor(DeityFieldTypes.BuryCorpse, 1);
            }

            comm.act(ATTypes.AT_ACTION, "You solemnly bury $p...", ch, obj, null, ToTypes.Character);
            comm.act(ATTypes.AT_ACTION, "$n solemnly buries $p...", ch, obj, null, ToTypes.Room);
            obj.ExtraFlags.SetBit((int)ItemExtraFlags.Buried);
            Macros.WAIT_STATE(ch, 10.GetNumberThatIsBetween(move / 2, 100));
        }