Exemplo n.º 1
0
        ////////////////

        /// <summary>
        /// Gets a unique code for a player's current state. Useful for detecting state changes.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="noContext">Omits team, pvp state, and name.</param>
        /// <param name="looksMatter">Includes appearance elements.</param>
        /// <returns></returns>
        public static int GetVanillaSnapshotHash(Player player, bool noContext, bool looksMatter)
        {
            int hash = EntityHelpers.GetVanillaSnapshotHash(player, noContext);
            int itemHash;

            hash ^= ("statLifeMax" + player.statLifeMax).GetHashCode();
            hash ^= ("statManaMax" + player.statManaMax).GetHashCode();
            hash ^= ("extraAccessory" + player.extraAccessory).GetHashCode();
            hash ^= ("difficulty" + player.difficulty).GetHashCode();

            if (!noContext)
            {
                hash ^= ("team" + player.team).GetHashCode();
                hash ^= ("hostile" + player.hostile).GetHashCode();                     //pvp?
                hash ^= ("name" + player.name).GetHashCode();
            }

            if (looksMatter)
            {
                hash ^= ("Male" + player.Male).GetHashCode();
                hash ^= ("skinColor" + player.skinColor).GetHashCode();
                hash ^= ("hair" + player.hair).GetHashCode();
                hash ^= ("hairColor" + player.hairColor).GetHashCode();
                hash ^= ("shirtColor" + player.shirtColor).GetHashCode();
                hash ^= ("underShirtColor" + player.underShirtColor).GetHashCode();
                hash ^= ("pantsColor" + player.pantsColor).GetHashCode();
                hash ^= ("shoeColor" + player.shoeColor).GetHashCode();
            }

            for (int i = 0; i < player.inventory.Length; i++)
            {
                Item item = player.inventory[i];
                if (item == null || !item.active || item.stack == 0)
                {
                    itemHash = ("inv" + i).GetHashCode();
                }
                else
                {
                    itemHash = i + ItemIdentityHelpers.GetVanillaSnapshotHash(item, noContext, true);
                }
                hash ^= itemHash;
            }
            for (int i = 0; i < player.armor.Length; i++)
            {
                Item item = player.armor[i];
                if (item == null || !item.active || item.stack == 0)
                {
                    itemHash = ("arm" + i).GetHashCode();
                }
                else
                {
                    itemHash = i + ItemIdentityHelpers.GetVanillaSnapshotHash(item, noContext, true);
                }
                hash ^= itemHash;
            }
            for (int i = 0; i < player.bank.item.Length; i++)
            {
                Item item = player.bank.item[i];
                if (item == null || !item.active || item.stack == 0)
                {
                    itemHash = ("bank" + i).GetHashCode();
                }
                else
                {
                    itemHash = i + ItemIdentityHelpers.GetVanillaSnapshotHash(item, noContext, true);
                }
                hash ^= itemHash;
            }
            for (int i = 0; i < player.bank2.item.Length; i++)
            {
                Item item = player.bank2.item[i];
                if (item == null || !item.active || item.stack == 0)
                {
                    itemHash = ("bank2" + i).GetHashCode();
                }
                else
                {
                    itemHash = i + ItemIdentityHelpers.GetVanillaSnapshotHash(item, noContext, true);
                }
                hash ^= itemHash;
            }
            for (int i = 0; i < player.bank3.item.Length; i++)
            {
                Item item = player.bank3.item[i];
                if (item == null || !item.active || item.stack == 0)
                {
                    itemHash = ("bank3" + i).GetHashCode();
                }
                else
                {
                    itemHash = i + ItemIdentityHelpers.GetVanillaSnapshotHash(item, noContext, true);
                }
                hash ^= itemHash;
            }
            return(hash);
        }