Example #1
0
        private static void Scavenge(CharacterInstance ch)
        {
            var            max  = 1;
            ObjectInstance best = null;

            foreach (var obj in ch.CurrentRoom.Contents)
            {
                if (obj.ExtraFlags.IsSet((int)ItemExtraFlags.Prototype) && !ch.Act.IsSet((int)ActFlags.Prototype))
                {
                    continue;
                }
                if (obj.WearFlags.IsSet(ItemWearFlags.Take) && obj.Cost > max &&
                    !obj.ExtraFlags.IsSet((int)ItemExtraFlags.Buried))
                {
                    best = obj;
                    max  = obj.Cost;
                }
            }

            if (best != null)
            {
                best.InRoom.RemoveFrom(best);
                best.AddTo(ch);
                comm.act(ATTypes.AT_ACTION, "$n gets $p.", ch, best, null, ToTypes.Room);
            }
        }
        private static bool EmptyInto(ObjectInstance obj, ObjectInstance destobj)
        {
            var retVal = false;

            foreach (var cobj in obj.Contents)
            {
                if (destobj.ItemType == ItemTypes.KeyRing && cobj.ItemType != ItemTypes.Key)
                {
                    continue;
                }
                if (destobj.ItemType == ItemTypes.Quiver && cobj.ItemType != ItemTypes.Projectile)
                {
                    continue;
                }
                if ((destobj.ItemType == ItemTypes.Container ||
                     destobj.ItemType == ItemTypes.KeyRing ||
                     destobj.ItemType == ItemTypes.Quiver) &&
                    (cobj.GetRealWeight() + destobj.GetRealWeight() > destobj.Value.ToList()[0]))
                {
                    continue;
                }

                cobj.RemoveFrom(cobj);
                destobj.AddTo(cobj);
                retVal = true;
            }
            return(retVal);
        }
Example #3
0
        private static ReturnTypes CloneObjectSpellAction(SkillData skill, int level, CharacterInstance ch, ObjectInstance obj)
        {
            switch (Macros.SPELL_POWER(skill))
            {
            case (int)SpellPowerTypes.Minor:
                if (CheckFunctions.CheckIfTrueCasting(
                        (ch.Level - obj.Level < 20) || (obj.Cost > ch.Level * ch.GetCurrentIntelligence() / 5),
                        skill, ch, CastingFunctionType.Failed, null, obj))
                {
                    return(ReturnTypes.None);
                }
                break;

            case (int)SpellPowerTypes.Greater:
                if (CheckFunctions.CheckIfTrueCasting((ch.Level - obj.Level < 5) ||
                                                      (obj.Cost > ch.Level * 10 * ch.GetCurrentIntelligence() * ch.GetCurrentWisdom()),
                                                      skill, ch, CastingFunctionType.Failed, null, obj))
                {
                    return(ReturnTypes.None);
                }
                break;

            case (int)SpellPowerTypes.Major:
                if (CheckFunctions.CheckIfTrueCasting((ch.Level - obj.Level < 0) ||
                                                      (obj.Cost > ch.Level * 50 * ch.GetCurrentIntelligence() * ch.GetCurrentWisdom()),
                                                      skill, ch, CastingFunctionType.Failed, null, obj))
                {
                    return(ReturnTypes.None);
                }

                ObjectInstance clonedObj = null;        // TODO Clone ObjectInstance
                clonedObj.Timer = !string.IsNullOrEmpty(skill.Dice) ? magic.ParseDiceExpression(ch, skill.Dice) : 0;
                clonedObj.AddTo(ch);
                ch.SuccessfulCast(skill, null, obj);
                break;

            default:
                if (CheckFunctions.CheckIfTrueCasting((ch.Level - obj.Level < 10) ||
                                                      (obj.Cost > ch.Level * ch.GetCurrentIntelligence() * ch.GetCurrentWisdom()),
                                                      skill, ch, CastingFunctionType.Failed, null, obj))
                {
                    return(ReturnTypes.None);
                }
                break;
            }

            return(ReturnTypes.None);
        }
Example #4
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);
        }
Example #5
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;
            }
        }