Example #1
0
        public static void RegisterUpdateObject(Type type)
        {
            try {
                object[] tmp = type.GetCustomAttributes(typeof(UpdateObjectAttribute), true);
                if (tmp.Length == 0)
                {
                    throw new ObjectUpdateManagerException(type.ToString() + " has no UpdateObjectAttribute");
                }
                UpdateObjectAttribute updateObjectAttribute = (UpdateObjectAttribute)tmp[0];
                if (updateObjectAttribute.MaxFields == -1)
                {
                    throw new ObjectUpdateManagerException("MaxFields is not set in UpdateObjectAttribute on " + type.ToString());
                }

                Hashtable tbl = new Hashtable();
                foreach (MemberValue value in MemberValue.GetMemberValues(type, typeof(UpdateValueAttribute), true, false))
                {
                    UpdateValueAttribute attrib = (UpdateValueAttribute)value.Attribute;
                    if (!checkType(attrib, type))
                    {
                        continue;
                    }
                    Type valueType = value.GetValueType();
                    if (valueType.IsArray == false)
                    {
                        if (!IsSubClass(valueType))
                        {
                            if (attrib.Field == -1)
                            {
                                throw new ObjectUpdateManagerException("Field was not set on " + type.Name + value.GetName());
                            }
                            if (value is IndexMemberValue)
                            {
                                IndexMemberValue indexValue = value as IndexMemberValue;
                                if (valueType == typeof(ulong) || valueType == typeof(long))
                                {
                                    AddUpdateValue(tbl, value, attrib.Field + indexValue.Index * 2);
                                }
                                else
                                {
                                    AddUpdateValue(tbl, value, attrib.Field + indexValue.Index);
                                }
                            }
                            else
                            {
                                AddUpdateValue(tbl, value, attrib.Field);
                            }
                        }
                        else
                        {
                            GetSubClassUpdateValues(tbl, value, attrib.Field == -1 ? 0 : attrib.Field, valueType, type);
                        }
                    }
                    else
                    {
                        if (attrib.ArraySize == -1)
                        {
                            throw new ObjectUpdateManagerException("ArraySize was not set on " + type.Name + "." + value.GetName());
                        }
                        if (attrib.Field == -1)
                        {
                            throw new ObjectUpdateManagerException("Field was not set on the array " + type.Name + "." + value.GetName());
                        }
                        if (attrib.NumSubFields == -1)
                        {
                            throw new ObjectUpdateManagerException("NumFields was not set on the subclass array " + type.Name + "." + value.GetName());
                        }
                        valueType = valueType.GetElementType();
                        for (int i = 0; i < attrib.ArraySize; i++)
                        {
                            IndexMemberValue indexValue = new IndexMemberValue(value, i);
                            GetSubClassUpdateValues(tbl, indexValue, attrib.Field + i * attrib.NumSubFields, valueType, type);
                        }
                    }
                }

                if (tbl.Count == 0)
                {
                    throw new ObjectUpdateManagerException("No update values in " + type.ToString());
                }
                UpdateObjectInfo uoi = new UpdateObjectInfo(tbl, updateObjectAttribute.MaxFields);
                m_updateObjectInfos[type] = uoi;
            } catch (Exception exp) {
                DebugLogger.Log("", exp);
            }
        }
Example #2
0
        public void DealDamage(PlayerObject pobj, int damage)
        {
            if (!this.Dead)
            {
                if (m_agrotable[pobj.CharacterID] == null)
                {
                    m_agrotable.Add(pobj.CharacterID, damage);
                }
                else
                {
                    int damagedealt = (int)m_agrotable[pobj.CharacterID];
                    damagedealt += damage;
                    m_agrotable[pobj.CharacterID] = damagedealt;
                }

                this.Health -= damage;
                if (this.Health < 1)
                {
                    this.Roaming = false;
                    EventManager.AddEvent(new CorpseDespawnEvent((UnitBase)this));
                    this.Health       = 0;
                    this.StandState   = UNITSTANDSTATE.DEAD;
                    this.Dead         = true;
                    this.DynamicFlags = 1;                     // If set to 1 there will be loot.
                    this.LootOwner    = pobj.GUID;
                    this.UpdateData();

                    try {
                        // Give xp to the right people.
                        int       exp             = StatManager.CalculateExp(this, pobj);
                        int       maxdamage       = 0;
                        Hashtable expdividergroup = new Hashtable();
                        Hashtable expdividersolo  = new Hashtable();
                        foreach (DictionaryEntry de in m_agrotable)
                        {
                            maxdamage += (int)de.Value;
                            WorldClient aclient = WorldServer.GetClientByCharacterID((uint)de.Key);
                            if (aclient.Player.Group == null)
                            {
                                expdividersolo.Add(aclient.Player.CharacterID, (int)de.Value);
                            }
                            else
                            {
                                if (expdividergroup[aclient.Player.Group.LeaderGUID] == null)
                                {
                                    expdividergroup.Add(aclient.Player.Group.LeaderGUID, (int)de.Value);
                                }
                                else
                                {
                                    int damagedealt = (int)expdividergroup[aclient.Player.Group.LeaderGUID];
                                    damagedealt += (int)de.Value;
                                    expdividergroup[aclient.Player.Group.LeaderGUID] = damagedealt;
                                }
                            }
                        }

                        // Solo players
                        foreach (DictionaryEntry de in expdividersolo)
                        {
                            float       expbit  = ((int)de.Value / (float)maxdamage);
                            WorldClient aclient = WorldServer.GetClientByCharacterID((uint)de.Key);
                            if (aclient != null)
                            {
                                aclient.Player.GainXp(Convert.ToInt32(exp * expbit), this.GUID);
                            }
                        }

                        // Group players
                        foreach (DictionaryEntry de in expdividergroup)
                        {
                            WorldClient aclient = WorldServer.GetClientByCharacterID(Convert.ToUInt32((ulong)de.Key));
                            if (aclient != null)
                            {
                                GroupObject gobj   = aclient.Player.Group;
                                float       expbit = (((int)de.Value / (float)maxdamage) / (float)gobj.Size);
                                for (int i = 0; i < gobj.Size; i++)
                                {
                                    gobj.Members[i].GainXp(Convert.ToInt32(exp * expbit), this.GUID);
                                }
                            }
                        }
                    } catch (Exception exp) {
                        DebugLogger.Log("", exp);
                    }
                }
                else
                {
                    this.UpdateData();
                    if (this.MobsRegenEvent == null)
                    {
                        this.MobsRegenEvent = new MobsRegenEvent(this);
                        EventManager.AddEvent(this.MobsRegenEvent);
                    }
                }
            }
        }