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

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

            var exit = ch.FindExit(firstArg, true);

            if (exit != null)
            {
                OpenDoor(ch, exit, firstArg);
                return;
            }

            var obj = ch.GetObjectOnMeOrInRoom(firstArg);

            if (obj != null)
            {
                OpenObject(ch, obj, firstArg);
                return;
            }

            ch.Printf("You see no %s here.", firstArg);
        }
예제 #2
0
        private static ObjectInstance GetDrinkSource(CharacterInstance ch, string arg)
        {
            var obj = string.IsNullOrEmpty(arg)
                ? ch.CurrentRoom.Contents.FirstOrDefault(x => x.ItemType == ItemTypes.Fountain)
                : ch.GetObjectOnMeOrInRoom(arg);

            return(CheckFunctions.CheckIfNullObject(ch, obj,
                                                    string.IsNullOrEmpty(arg) ? "Drink what?" : "You can't find it.") ? obj : obj);
        }
예제 #3
0
        private static void EmptyIntoObject(CharacterInstance ch, ObjectInstance obj, string arg)
        {
            var destObj = ch.GetObjectOnMeOrInRoom(arg);

            if (CheckFunctions.CheckIfNullObject(ch, destObj, "You can't find it."))
            {
                return;
            }
            if (CheckFunctions.CheckIfEquivalent(ch, destObj, obj, "You can't empty something into itself!"))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch,
                                           destObj.ItemType != ItemTypes.Container && destObj.ItemType != ItemTypes.KeyRing &&
                                           destObj.ItemType != ItemTypes.Quiver, "That's not a container!"))
            {
                return;
            }

            if (((int)destObj.Values.Flags).IsSet(ContainerFlags.Closed))
            {
                comm.act(ATTypes.AT_PLAIN, "The $d is closed.", ch, null, destObj.Name, ToTypes.Character);
                return;
            }

            destObj.Split();

            if (obj.Empty(destObj))
            {
                comm.act(ATTypes.AT_ACTION, "You empty $p into $P.", ch, obj, destObj, ToTypes.Character);
                comm.act(ATTypes.AT_ACTION, "$n empties $p into $P.", ch, obj, destObj, ToTypes.Room);

                if (destObj.CarriedBy == null && GetSaveFlags().IsSet(AutoSaveFlags.Empty))
                {
                    save.save_char_obj(ch);
                }
            }
            else
            {
                comm.act(ATTypes.AT_ACTION, "$P is too full.", ch, obj, destObj, ToTypes.Character);
            }
        }
예제 #4
0
        public static void do_pull(CharacterInstance ch, string argument)
        {
            var firstArg = argument.FirstWord();

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

            if (handler.FindObject_CheckMentalState(ch))
            {
                return;
            }

            var obj = ch.GetObjectOnMeOrInRoom(firstArg);

            if (obj == null)
            {
                comm.act(ATTypes.AT_PLAIN, "I see no $T here.", ch, null, null, ToTypes.Character);
                return;
            }

            PullOrPush.pullorpush(ch, obj, true);
        }
예제 #5
0
        public static ObjectInstance FindObject(CharacterInstance ch, string argument, bool carryonly)
        {
            var tuple = argument.FirstArgument();
            var arg1  = tuple.Item1;

            tuple = tuple.Item2.FirstArgument();
            var arg2      = tuple.Item1;
            var remainder = tuple.Item2;

            if (arg2.EqualsIgnoreCase("from") && !string.IsNullOrEmpty(remainder))
            {
                tuple     = remainder.FirstArgument();
                arg2      = tuple.Item1;
                remainder = tuple.Item2;
            }

            ObjectInstance obj;

            if (string.IsNullOrEmpty(arg2))
            {
                obj = carryonly ? ch.GetCarriedObject(arg1) : ch.GetObjectOnMeOrInRoom(arg1);
                if (CheckFunctions.CheckIfTrue(ch, obj == null && carryonly, "You do not have that item."))
                {
                    return(null);
                }

                if (obj == null)
                {
                    comm.act(ATTypes.AT_PLAIN, "I see no $T here.", ch, null, arg1, ToTypes.Character);
                    return(null);
                }

                return(obj);
            }

            ObjectInstance container = null;

            if (CheckFunctions.CheckIfTrue(ch,
                                           carryonly && (container = ch.GetCarriedObject(arg2)) == null &&
                                           (container = ch.GetWornObject(arg2)) == null, "You do not have that item."))
            {
                return(null);
            }

            if (!carryonly && (container = ch.GetObjectOnMeOrInRoom(arg2)) == null)
            {
                comm.act(ATTypes.AT_PLAIN, "I see no $T here.", ch, null, arg2, ToTypes.Character);
                return(null);
            }

            if (!container.ExtraFlags.IsSet((int)ItemExtraFlags.Covering) && container.Value.ToList()[1].IsSet(ContainerFlags.Closed))
            {
                comm.act(ATTypes.AT_PLAIN, "The $d is closed.", ch, null, container.Name, ToTypes.Character);
                return(null);
            }

            obj = ch.GetObjectInList(container.Contents, arg1);
            if (obj == null)
            {
                comm.act(ATTypes.AT_PLAIN, container.ExtraFlags.IsSet((int)ItemExtraFlags.Covering)
                    ? "I see nothing like that beneath $p."
                    : "I see nothing like that in $p.", ch, container, null, ToTypes.Character);
            }

            return(obj);
        }
예제 #6
0
        public static void do_apply(CharacterInstance ch, string argument)
        {
            var firstArg = argument.FirstWord();

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

            var secondArg = argument.SecondWord();

            if (CheckFunctions.CheckIfNotNullObject(ch, ch.CurrentFighting, "You're too busy fighting..."))
            {
                return;
            }
            if (handler.FindObject_CheckMentalState(ch))
            {
                return;
            }

            var salve = ch.GetCarriedObject(firstArg);

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

            CharacterInstance victim;
            ObjectInstance    obj = null;

            if (string.IsNullOrEmpty(secondArg))
            {
                victim = ch;
            }
            else
            {
                victim = ch.GetCharacterInRoom(secondArg);
                obj    = ch.GetObjectOnMeOrInRoom(secondArg);

                if (CheckFunctions.CheckIfTrue(ch, victim == null && obj == null, "Apply it to what or whom?"))
                {
                    return;
                }
            }

            if (CheckFunctions.CheckIfNotNullObject(ch, obj, "You can't do that... yet."))
            {
                return;
            }
            if (CheckFunctions.CheckIfNotNullObject(ch, victim.CurrentFighting,
                                                    "Wouldn't work very well while they're fighting..."))
            {
                return;
            }

            if (salve.ItemType != ItemTypes.Salve)
            {
                ApplyNonSalve(salve, ch, victim);
                return;
            }

            salve.Split();
            salve.Values.Charges -= 1;

            if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, salve, null, null))
            {
                UseSalve(salve, ch, victim);
            }

            Macros.WAIT_STATE(ch, salve.Values.Delay);
            var retcode = ch.ObjectCastSpell((int)salve.Values.Skill1ID, (int)salve.Values.SpellLevel, victim);

            if (retcode == ReturnTypes.None)
            {
                retcode = ch.ObjectCastSpell((int)salve.Values.Skill2ID, (int)salve.Values.SpellLevel, victim);
            }
            if (retcode == ReturnTypes.CharacterDied || retcode == ReturnTypes.BothDied)
            {
                throw new CharacterDiedException("Salve {0}, Actor {1}, Victim {2}", salve.ID, ch.ID, victim.ID);
            }

            if (!handler.obj_extracted(salve) && salve.Values.Charges <= 0)
            {
                salve.Extract();
            }
        }
예제 #7
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;
            }
        }
예제 #8
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));
        }