Exemplo n.º 1
0
        /// <summary>
        /// Equip a char with an object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="iWear">The equipment slot to place the object on.</param>
        public void EquipObject( ref Object obj, ObjTemplate.WearLocation iWear )
        {
            int aff;

            if( obj == null )
                return;

            if( Object.GetEquipmentOnCharacter( this, iWear ) )
            {
                string buf = String.Format( "CharData.EquipObject(): {0} already equipped at slot {1}.", Name, iWear );
                Log.Error( buf, 0 );
                return;
            }

            if( ( obj.HasFlag( ObjTemplate.ITEM_ANTI_EVIL ) && IsEvil() )
                    || ( obj.HasFlag( ObjTemplate.ITEM_ANTI_GOOD ) && IsGood() )
                    || ( obj.HasFlag( ObjTemplate.ITEM_ANTI_NEUTRAL ) && IsNeutral() ) )
            {
                SocketConnection.Act( "You are zapped by $p&n and drop it.", this, obj, null, SocketConnection.MessageTarget.character );
                SocketConnection.Act( "$n&n is zapped by $p&n and drops it.", this, obj, null, SocketConnection.MessageTarget.room );
                obj.RemoveFromChar();
                obj.AddToRoom( InRoom );
                return;
            }

            ArmorPoints -= Object.GetArmorClassModifer( obj, iWear );
            obj.WearLocation = iWear;
            CarryNumber--;

            foreach (Affect affect in obj.ObjIndexData.Affected)
            {
                ApplyAffectModifiers(affect, true);
            }
            foreach (Affect affect in obj.Affected)
            {
                ApplyAffectModifiers(affect, true);
            }

            if (obj.ItemType == ObjTemplate.ObjectType.light
                    && obj.Values[2] != 0 && InRoom)
            {
                ++InRoom.Light;
            }

            for( aff = 0; aff < Limits.NUM_AFFECT_VECTORS; aff++ )
                AffectedBy[ aff ] = AffectedBy[ aff ] | obj.AffectedBy[ aff ];

            if (!IsNPC() && Socket.Terminal == SocketConnection.TerminalType.TERMINAL_ENHANCED)
            {
                Command.Equipment(this, new string[] { "" } );
            }

            return;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks whether a character can see an objects.  Returns true if yes, false if no.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool CanSeeObj( CharData ch, Object obj )
        {
            if( obj == null )
            {
                Log.Error("Calling CanSeeObj with no obj data!", 0);
                return false;
            }

            if( ch == null )
            {
                Log.Error("Calling CanSeeObj with no CharData!", 0);
                return false;
            }

            if (!ch.IsNPC() && ch.HasActionBit(PC.PLAYER_GODMODE))
                return true;

            if (ch.IsAffected(Affect.AFFECT_BLIND) || ch.CurrentPosition <= Position.sleeping)
                return false;

            if( obj.ItemType == ObjTemplate.ObjectType.light && obj.Values[ 2 ] != 0 )
                return true;

            if( obj.HasFlag( ObjTemplate.ITEM_SECRET )
                    && !( ch.HasInnate( Race.RACE_DETECT_HIDDEN )
                         || ch.IsAffected( Affect.AFFECT_DETECT_HIDDEN ) ) )
                return false;

            if( obj.HasFlag( ObjTemplate.ITEM_INVIS )
                    && !ch.HasInnate( Race.RACE_DETECT_INVIS )
                    && !ch.IsAffected( Affect.AFFECT_DETECT_INVIS ) )
                return false;

            if( obj.HasFlag( ObjTemplate.ITEM_LIT ) )
                return true;

            if( ch.InRoom && ch.InRoom.IsDark() && !( ch.HasInnate( Race.RACE_ULTRAVISION )
                         || ch.IsAffected( Affect.AFFECT_ULTRAVISION ) ) )
                return false;

            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks whether a character can drop an object.  Returns true if it can be dropped, false if not.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool CanDropObject( Object obj )
        {
            if( !obj.HasFlag( ObjTemplate.ITEM_NODROP ) )
                return true;

            if( !IsNPC() && Level >= Limits.LEVEL_AVATAR )
                return true;

            return false;
        }
Exemplo n.º 4
0
        public static void GetObject(CharData ch, Object obj, Object container)
        {
            if (!obj.HasWearFlag(ObjTemplate.WEARABLE_CARRY))
            {
                ch.SendText("You can't pick that up.\r\n");
                return;
            }

            if (obj._itemType != ObjTemplate.ObjectType.money)
            {
                if (ch.CarryWeight + obj.GetWeight() > ch.MaxCarryWeight())
                {
                    SocketConnection.Act("$p&n is quite literally the &+Ystraw&n that would break the &n&+ycamel&n's back.", ch, obj, null, SocketConnection.MessageTarget.character);
                    return;
                }
            }

            if (container != null)
            {
                SocketConnection.Act("You get $p&n from $P&n.", ch, obj, container, SocketConnection.MessageTarget.character);
                SocketConnection.Act("$n&n retrieves $p&n from $P&n.", ch, obj, container, SocketConnection.MessageTarget.room);
                obj.RemoveFromObject();
                // Fix for corpse EQ dupe on crash
                if (container._itemType == ObjTemplate.ObjectType.pc_corpse)
                {
                    Database.CorpseList.Save();
                }
            }
            else
            {
                SocketConnection.Act("You get $p&n.", ch, obj, container, SocketConnection.MessageTarget.character);
                SocketConnection.Act("$n&n picks up $p&n.", ch, obj, container, SocketConnection.MessageTarget.room);
                obj.RemoveFromRoom();
            }

            if (obj.HasFlag(ObjTemplate.ITEM_ANTI_EVIL) && ch.IsEvil())
            {
                SocketConnection.Act("&+LYou are &n&+rburned&+L by holy &+Rfire&+L from $p&+L.  Ouch!&n", ch, obj, null,
                     SocketConnection.MessageTarget.character);
                SocketConnection.Act("$n&+L is &n&+rburned&+L by holy &+Rfire&+L from &n$p&+L!&n", ch, obj, null, SocketConnection.MessageTarget.room);
                Combat.InflictSpellDamage(ch, ch, 20, "burning hands", AttackType.DamageType.white_magic);
                obj.AddToRoom(ch.InRoom);
                return;
            }

            if (obj.HasFlag(ObjTemplate.ITEM_ANTI_EVIL) && ch.IsEvil())
            {
                SocketConnection.Act("&+LYou are &n&+rburned&+L by holy &+Rfire&+L from $p&+L.  Ouch!&n", ch, obj, null,
                     SocketConnection.MessageTarget.character);
                SocketConnection.Act("$n&+L is &n&+rburned&+L by holy &+Rfire&+L from &n$p&+L!&n", ch, obj, null, SocketConnection.MessageTarget.room);
                Combat.InflictSpellDamage(ch, ch, 20, "burning hands", AttackType.DamageType.white_magic);
                obj.AddToRoom(ch.InRoom);
                return;
            }

            if (obj.HasFlag(ObjTemplate.ITEM_ANTI_GOOD) && ch.IsGood())
            {
                SocketConnection.Act("&+LYou are &n&+rconsumed&+L by &+Rfire&+L and &+Ldespair&n from $p&+L!&n", ch, obj, null, SocketConnection.MessageTarget.character);
                SocketConnection.Act("$n&+L is &n&+rengulfed&+L by an abundancy of &+Rflames&+L from &n$p&+L!&n", ch, obj, null, SocketConnection.MessageTarget.room);
                Combat.InflictSpellDamage(ch, ch, 20, "burning hands", AttackType.DamageType.white_magic);
                obj.AddToRoom(ch.InRoom);
                return;
            }

            if (obj._itemType == ObjTemplate.ObjectType.money)
            {
                int amount = obj._values[0] + obj._values[1] + obj._values[2] + obj._values[3];
                ch.ReceiveCopper(obj._values[0]);
                ch.ReceiveSilver(obj._values[1]);
                ch.ReceiveGold(obj._values[2]);
                ch.ReceivePlatinum(obj._values[3]);

                if (amount > 1)
                {
                    string text = String.Format("You pick up");
                    string text2;
                    if (obj._values[3] > 0)
                    {
                        text2 = String.Format(" {0} &+Wplatinum&n", obj._values[3]);
                        if (obj._values[0] > 0 || obj._values[1] > 0 || obj._values[2] > 0)
                        {
                            text2 += ",";
                        }
                        text += text2;
                    }
                    if (obj._values[2] > 0)
                    {
                        text2 = String.Format(" {0} &+Ygold&n", obj._values[2]);
                        if (obj._values[0] > 0 || obj._values[1] > 0)
                        {
                            text2 += ",";
                        }
                        text += text2;
                    }
                    if (obj._values[1] > 0)
                    {
                        text2 = String.Format(" {0} &n&+wsilver&n", obj._values[1]);
                        if (obj._values[0] > 0)
                        {
                            text2 += ",";
                        }
                        text += text2;
                    }
                    if (obj._values[0] > 0)
                    {
                        text2 = String.Format(" {0} &n&+ycopper&n", obj._values[0]);
                        text += text2;
                    }
                    text += " coins.\r\n";
                    ch.SendText(text);
                }

                obj.RemoveFromWorld();
            }
            else
            {
                obj.ObjToChar(ch);
                // Prevent item duplication.
                CharData.SavePlayer(ch);
            }

            return;
        }
Exemplo n.º 5
0
        /// <summary>
        /// This function's main access commands are wear, wield, and hold, which have the
        /// following flow:
        /// wear:  Command.Wear, wear_obj, equip_hand
        /// wield: Command.Wield, equip_hand
        /// hold:  Command.Hold, equip_hand 
        /// 
        /// We assume by this point that the character is physically able to use the item and will be able
        /// to equip it however specified.  Those checks are performed by WearObject(), Equip(), and Hold().
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="obj"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool EquipInHand(CharData ch, Object obj, int type)
        {
            int weight = 0;
            ObjTemplate.WearLocation firstAvail = ObjTemplate.WearLocation.none;
            ObjTemplate.WearLocation secondAvail = ObjTemplate.WearLocation.none;
            ObjTemplate.WearLocation lastAvail = ObjTemplate.WearLocation.none;

            Object hand1 = GetEquipmentOnCharacter(ch, ObjTemplate.WearLocation.hand_one);
            Object hand2 = GetEquipmentOnCharacter(ch, ObjTemplate.WearLocation.hand_two);
            Object hand3 = GetEquipmentOnCharacter(ch, ObjTemplate.WearLocation.hand_three);
            Object hand4 = GetEquipmentOnCharacter(ch, ObjTemplate.WearLocation.hand_four);
            if (hand1 && (hand1._itemType == ObjTemplate.ObjectType.weapon || hand1._itemType == ObjTemplate.ObjectType.ranged_weapon))
                weight += hand1.GetWeight();
            if (hand2 && (hand2._itemType == ObjTemplate.ObjectType.weapon || hand2._itemType == ObjTemplate.ObjectType.ranged_weapon))
                weight += hand2.GetWeight();
            if (hand3 && (hand3._itemType == ObjTemplate.ObjectType.weapon || hand3._itemType == ObjTemplate.ObjectType.ranged_weapon))
                weight += hand3.GetWeight();
            if (hand4 && (hand4._itemType == ObjTemplate.ObjectType.weapon || hand4._itemType == ObjTemplate.ObjectType.ranged_weapon))
                weight += hand4.GetWeight();

            if (ch.GetRace() != Race.RACE_THRIKREEN)
            {
                if (hand3)
                    Log.Error("non-thrikreen wielding item in hand3", 0);
                if (hand4)
                    Log.Error("non-thrikreen wielding item in hand4", 0);
            }

            // Find number of hand slots used and first available hand.
            // Be sure to handle twohanded stuff.
            if (hand4 && hand4.HasFlag(ObjTemplate.ITEM_TWOHANDED))
            {
                Log.Error("Twohanded weapon in fourth hand -- this is not possible.", 0);
            }
            if (hand3 && hand3.HasFlag(ObjTemplate.ITEM_TWOHANDED))
            {
                if (hand4)
                {
                    Log.Error("Twohanded weapon in third hand with fourth hand holding twohanded weapon -- this is not possible, all twohanded must have a blank hand after it.", 0);
                }
                hand4 = hand3;
            }
            if (hand2 && hand2.HasFlag(ObjTemplate.ITEM_TWOHANDED))
            {
                if (hand3)
                {
                    Log.Error("Twohanded weapon in second hand with third hand holding twohanded weapon -- this is not possible, all twohanded must have a blank hand after it.", 0);
                }
                hand2 = hand3;
            }
            if (!ch.HasInnate(Race.RACE_EXTRA_STRONG_WIELD))
            {
                if (hand1 && hand1.HasFlag(ObjTemplate.ITEM_TWOHANDED))
                {
                    if (hand2)
                    {
                        Log.Error("Twohanded weapon in second hand with first hand holding twohanded weapon -- this is not possible, all twohanded must have a blank hand after it.", 0);
                    }
                    hand2 = hand1;
                }
            }

            if (obj.HasFlag(ObjTemplate.ITEM_TWOHANDED)
                    && !ch.HasInnate(Race.RACE_EXTRA_STRONG_WIELD))
            {
                if (ch.GetRace() == Race.RACE_THRIKREEN && !hand4)
                {
                    firstAvail = ObjTemplate.WearLocation.hand_four;
                    lastAvail = ObjTemplate.WearLocation.hand_four;
                }
                if (ch.GetRace() == Race.RACE_THRIKREEN && !hand3)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_three;
                    secondAvail = firstAvail;
                    firstAvail = ObjTemplate.WearLocation.hand_three;
                }
                if (!hand2)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_two;
                    secondAvail = firstAvail;
                    firstAvail = ObjTemplate.WearLocation.hand_two;
                }
                if (!hand1)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_one;
                    secondAvail = firstAvail;
                    firstAvail = ObjTemplate.WearLocation.hand_one;
                }

                if (firstAvail == 0)
                {
                    ch.SendText("Your hands are full!\r\n");
                    return false;
                }
                if (secondAvail == 0)
                {
                    ch.SendText("You need two hands free to wield that!\r\n");
                    return false;
                }
            }
            else if (obj.HasFlag(ObjTemplate.ITEM_TWOHANDED))
            {
                if (ch.GetRace() == Race.RACE_THRIKREEN && !hand4)
                {
                    firstAvail = ObjTemplate.WearLocation.hand_four;
                }
                if (ch.GetRace() == Race.RACE_THRIKREEN && !hand3)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_three;
                    secondAvail = firstAvail;
                    firstAvail = ObjTemplate.WearLocation.hand_three;
                }
                if (!hand2)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_two;
                    secondAvail = firstAvail;
                    firstAvail = ObjTemplate.WearLocation.hand_two;
                }
                if (!hand1)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_one;
                    secondAvail = ObjTemplate.WearLocation.hand_one;
                    firstAvail = ObjTemplate.WearLocation.hand_one;
                }

                if (firstAvail == 0)
                {
                    ch.SendText("Your hands are full!\r\n");
                    return false;
                }
                if (secondAvail == 0)
                {
                    ch.SendText("You need two hands free to wield that!\r\n");
                    return false;
                }
            }
            else
            {
                if (ch.GetRace() == Race.RACE_THRIKREEN && !hand4)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_four;
                    firstAvail = ObjTemplate.WearLocation.hand_four;
                }
                if (ch.GetRace() == Race.RACE_THRIKREEN && !hand3)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_three;
                    firstAvail = ObjTemplate.WearLocation.hand_three;
                }
                if (!hand2)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_two;
                    firstAvail = ObjTemplate.WearLocation.hand_two;
                }
                if (hand1 == null)
                {
                    if (lastAvail == 0)
                        lastAvail = ObjTemplate.WearLocation.hand_one;
                    firstAvail = ObjTemplate.WearLocation.hand_one;
                }

                if (firstAvail == 0)
                {
                    ch.SendText("Your hands are full!\r\n");
                    return false;
                }
            }

            // Successful hand availability, send message and ready the item.
            // Twohanded shields, held items, and lights are equipped primary.
            // This could annoy ogres/thris but twohanded versions of these items
            // are so rare it's not likely to be an issue.
            switch (type)
            {
                case EQUIP_HOLD:
                    if (!obj.HasFlag(ObjTemplate.ITEM_TWOHANDED))
                        ch.EquipObject(ref obj, lastAvail);
                    else
                        ch.EquipObject(ref obj, firstAvail);
                    break;
                case EQUIP_SHIELD:
                    SocketConnection.Act("You strap $p&n to your arm.", ch, obj, null, SocketConnection.MessageTarget.character);
                    SocketConnection.Act("$n&n straps $p&n to $s arm.", ch, obj, null, SocketConnection.MessageTarget.room);
                    if (!obj.HasFlag(ObjTemplate.ITEM_TWOHANDED))
                        ch.EquipObject(ref obj, lastAvail);
                    else
                        ch.EquipObject(ref obj, firstAvail);
                    break;
                case EQUIP_LIGHT:
                    if (obj._itemType == ObjTemplate.ObjectType.light && obj._values[2] != 0)
                    {
                        SocketConnection.Act("You &n&+rli&+Rght&n $p&n and hold it before you.", ch, obj, null, SocketConnection.MessageTarget.character);
                        SocketConnection.Act("$n&n &+Rlig&n&+rhts&n $p&n and holds it before $m.", ch, obj, null, SocketConnection.MessageTarget.room);
                    }
                    else
                    {
                        SocketConnection.Act("You hold the &+Lspent&n remains of $p&n.", ch, obj, null, SocketConnection.MessageTarget.character);
                        SocketConnection.Act("$n&n holds the spent husk of $p&n.", ch, obj, null, SocketConnection.MessageTarget.room);
                    }
                    if (!obj.HasFlag(ObjTemplate.ITEM_TWOHANDED))
                        ch.EquipObject(ref obj, lastAvail);
                    else
                        ch.EquipObject(ref obj, firstAvail);
                    break;
                case EQUIP_WIELD:
                    // Have to check for dual wield skill, and for total weight of weapons.
                    if (firstAvail != ObjTemplate.WearLocation.hand_one)
                    {
                        // Those without dual wield cannot wield anything in their second hand.  Include thrikreen
                        if (!ch.IsNPC() && !ch.HasSkill("dual wield"))
                        {
                            ch.SendText("You lack the skills to wield a weapon in anything but your primary hand.\r\n");
                            return false;
                        }
                    }
                    if ((weight + obj.GetWeight()) > StrengthModifier.Table[ch.GetCurrStr()].WieldWeight)
                    {
                        SocketConnection.Act("Your meager strength is overwhelmed by $p&n.", ch, obj, null, SocketConnection.MessageTarget.character);
                        return false;
                    }
                    SocketConnection.Act("You wield $p&n.", ch, obj, null, SocketConnection.MessageTarget.character);
                    SocketConnection.Act("$n&n brandishes $p&n.", ch, obj, null, SocketConnection.MessageTarget.room);
                    ch.EquipObject(ref obj, firstAvail);
                    break;
            }

            // Objects with a trap activated on wear.
            if (obj._trap != null && obj._trap.CheckTrigger( Trap.TriggerType.wear))
            {
                ch.SetOffTrap(obj);
                if (ch.CurrentPosition == Position.dead)
                    return false;
            }

            return true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the text representation for all of the flags on an item.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ItemString(Object obj)
        {
            string text = String.Empty;
            int count;

            for (count = 0; count < BitvectorFlagType.ItemFlags.Length; count++)
            {
                if (obj.HasFlag(BitvectorFlagType.ItemFlags[count].BitvectorData))
                {
                    text += " ";
                    text += BitvectorFlagType.ItemFlags[count].Name;
                }
            }

            return (!String.IsNullOrEmpty(text)) ? text.Substring(1) : "none";
        }
Exemplo n.º 7
0
        /// <summary>
        /// Formats an object for display to a character.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="ch"></param>
        /// <param name="shortDisplay"></param>
        /// <returns></returns>
        public static string FormatObjectToCharacter(Object obj, CharData ch, bool shortDisplay)
        {
            string text = String.Empty;

            if (obj == null || ch == null)
            {
                Log.Error("format_obj_to_char: null ch or obj.", 0);
                return null;
            }

            if (shortDisplay)
            {
                if (obj.ShortDescription.Length > 0)
                {
                    text += obj.ShortDescription;
                }
                text += " ";
            }

            if (obj.HasFlag(ObjTemplate.ITEM_NOSHOW) && ch.IsImmortal())
            {
                text += "&n(&+LNoshow&n) ";
            }
            else if (obj.HasFlag(ObjTemplate.ITEM_NOSHOW))
            {
                return text;
            }
            if (obj.HasFlag(ObjTemplate.ITEM_INVIS))
            {
                text += "&n(&+LInvis&n) ";
            }
            if ((ch.IsAffected( Affect.AFFECT_DETECT_EVIL) || ch.HasInnate(Race.RACE_DETECT_ALIGN)
                    || ch.IsClass(CharClass.Names.antipaladin) || ch.IsClass(CharClass.Names.paladin))
                    && obj.HasFlag(ObjTemplate.ITEM_EVIL))
            {
                text += "&n(&+LDark Aura&n) ";
            }
            if ((ch.IsAffected(Affect.AFFECT_DETECT_GOOD) || ch.HasInnate(Race.RACE_DETECT_ALIGN)
                    || ch.IsClass(CharClass.Names.antipaladin) || ch.IsClass(CharClass.Names.paladin))
                    && obj.HasFlag(ObjTemplate.ITEM_BLESS))
            {
                text += "&n(&+WLight Aura&n) ";
            }
            if (obj.HasFlag(ObjTemplate.ITEM_MAGIC) && (ch.IsAffected(Affect.AFFECT_DETECT_MAGIC) ||
                (!ch.IsNPC() && ch.HasActionBit(PC.PLAYER_GODMODE))))
            {
                text += "&n(&+BMagic&n) ";
            }
            if (obj.HasFlag(ObjTemplate.ITEM_GLOW))
            {
                text += "&n(&+CGlowing&n) ";
            }
            if (obj.HasFlag(ObjTemplate.ITEM_LIT))
            {
                text += "&n(&+WIlluminating&n) ";
            }
            if (obj.HasFlag(ObjTemplate.ITEM_SECRET) && (ch.IsAffected(Affect.AFFECT_DETECT_HIDDEN) ||
                (!ch.IsNPC() && ch.HasActionBit(PC.PLAYER_GODMODE))))
            {
                text += "&n(&+yHidden&n) ";
            }

            if (!shortDisplay)
            {
                if (obj.ItemType == ObjTemplate.ObjectType.pc_corpse && (ch.IsImmortal() || (int)ch.GetRacewarSide() == obj.Values[4]))
                {
                    text += "The " + obj.ShortDescription + " is lying here.";
                }
                else if (obj.FullDescription.Length > 0)
                {
                    text += obj.FullDescription;
                }
            }

            text += "&n";

            return text;
        }