コード例 #1
0
        private static bool DynamicMatchType(ArrayList array, Mobile m)
        {
            if (array == null || m == null)
            {
                return(false);
            }

            foreach (object o in array)
            {
                if (o is XmlDynamicFaction && XmlDynamicFaction.MatchFaction(m, ((XmlDynamicFaction)o).Name))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: XmlMobFactions.cs プロジェクト: pallop/Servuo
        // this method returns a list of the group types that the mobile belongs based upon dynamic factions
        public static List <GroupTypes> DynamicFindGroups(Mobile m)
        {
            if (m == null)
            {
                return(null);
            }

            List <GroupTypes> list = new List <XmlMobFactions.GroupTypes>();

            foreach (Group g in KillGroups)
            {
                if (XmlDynamicFaction.MatchFaction(m, g.DynamicFaction))
                {
                    list.Add(g.GroupType);
                }
            }

            return(list);
        }
コード例 #3
0
ファイル: XmlMobFactions.cs プロジェクト: pallop/Servuo
        public override void OnKill(Mobile killed, Mobile killer)
        {
            base.OnKill(killed, killer);

            // supports ignoring XmlPoints challenges
            if (m_ChallengeStatus)
            {
                m_ChallengeStatus = false;
                return;
            }

            if (killed == null || killer == null || killer == killed)
            {
                return;
            }

            // check for within guild kills and ignore them
            if (SameGuild(killed, killer))
            {
                return;
            }

            // this calculates the base faction level that will be gained/lost based upon the fame of the killed mob
            double value = (double)(killed.Fame / 1000.0);

            if (value <= 0)
            {
                value = 1;
            }

            // calculates credits gained in a similar way
            int cval = (int)(killed.Fame * m_CreditScale);

            if (cval <= 0)
            {
                cval = 1;
            }

            Credits += cval;

            // prepare the group lists that will be checked for faction
            List <XmlMobFactions.Group> glist  = null;
            List <XmlMobFactions.Group> dglist = null;

            // check to see whether this mob type has already been hashed into a group list
            if (!GroupHash.TryGetValue(killed.GetType(), out glist) || glist == null)
            {
                // otherwise look it up the slow way and prepare a hash entry for it at the same time
                // unless it is using dynamic faction
                glist = new List <XmlMobFactions.Group>();
                foreach (Group g in KillGroups)
                {
                    if (MatchType(g.Members, killed))
                    {
                        glist.Add(g);
                    }
                }
                GroupHash[killed.GetType()] = glist;
            }

            // have to look up dynamic factions the exhaustive way
            // does this mob have dynamic faction assignments?
            XmlAttachment dynam = XmlAttach.FindAttachment(killed, typeof(XmlDynamicFaction));

            if (dynam != null)
            {
                //if(XmlAttach.FindAttachment(XmlAttach.MobileAttachments, killed, typeof(XmlDynamicFaction)) != null)
                //{
                dglist = new List <XmlMobFactions.Group>();
                foreach (Group g in KillGroups)
                {
                    if (XmlDynamicFaction.MatchFaction(killed, g.DynamicFaction))
                    {
                        dglist.Add(g);
                    }
                }
            }

            List <List <XmlMobFactions.Group> > alist = new List <List <XmlMobFactions.Group> >();

            if (glist != null && glist.Count > 0)
            {
                alist.Add(glist);
            }
            if (dglist != null && dglist.Count > 0)
            {
                alist.Add(dglist);
            }

            //  go through this with static and dynamic factions
            foreach (List <XmlMobFactions.Group> al in alist)
            {
                foreach (Group g in al)
                {
                    // tabulate the faction loss from target group allies
                    if (g.Allies != null && g.Allies.Length > 0)
                    {
                        for (int i = 0; i < g.Allies.Length; i++)
                        {
                            Group ally = g.Allies[i];

                            int facloss = 0;
                            try
                            {
                                facloss = (int)(value * g.AllyLoss[i]);
                            }
                            catch {}
                            if (facloss <= 0)
                            {
                                facloss = 1;
                            }

                            int p = GetFactionLevel(ally.GroupType) - facloss;
                            SetFactionLevel(ally.GroupType, p);
                            if (verboseMobFactions)
                            {
                                killer.SendMessage("lost {0} faction {1}", ally.GroupType, facloss);
                            }
                        }
                    }

                    // tabulate the faction gain from target group opponents
                    if (g.Opponents != null && g.Opponents.Length > 0)
                    {
                        for (int i = 0; i < g.Opponents.Length; i++)
                        {
                            Group opp = g.Opponents[i];

                            int facgain = 0;
                            try
                            {
                                facgain = (int)(value * g.OpponentGain[i]);
                            }
                            catch {}
                            if (facgain <= 0)
                            {
                                facgain = 1;
                            }

                            int p = GetFactionLevel(opp.GroupType) + facgain;
                            SetFactionLevel(opp.GroupType, p);
                            if (verboseMobFactions)
                            {
                                killer.SendMessage("gained {0} faction {1}", opp.GroupType, facgain);
                            }
                        }
                    }
                }
            }

            m_EndTime = DateTime.UtcNow + Refractory;
        }