Ejemplo n.º 1
0
 public void ApplyForceReaction(uint faction_id, ReputationRank rank, bool apply)
 {
     if (apply)
     {
         _forcedReactions[faction_id] = rank;
     }
     else
     {
         _forcedReactions.Remove(faction_id);
     }
 }
Ejemplo n.º 2
0
        ReputationRank ReputationToRank(FactionRecord factionEntry, int standing)
        {
            ReputationRank rank = ReputationRank.Min;

            var friendshipReactions = Global.DB2Mgr.GetFriendshipRepReactions(factionEntry.FriendshipRepID);

            if (!friendshipReactions.Empty())
            {
                rank = ReputationToRankHelper(friendshipReactions, standing, (FriendshipRepReactionRecord frr) => { return(frr.ReactionThreshold); });
            }
            else
            {
                rank = ReputationToRankHelper(ReputationRankThresholds, standing, (int threshold) => { return(threshold); });
            }

            return(rank);
        }
Ejemplo n.º 3
0
        public void LoadFromDB()
        {
            // Set initial reputations (so everything is nifty before DB data load)
            Initialize();

            SQLResult result = DB.Characters.Select("SELECT faction, standing, flags FROM character_reputation WHERE guid = {0}", _player.GetGUIDLow());

            if (result.Count != 0)
            {
                for (var i = 0; i < result.Count; i++)
                {
                    var factionEntry = DBCStorage.FactionStorage.LookupByKey(result.Read <uint>(i, 0));
                    if (factionEntry != null && factionEntry.reputationListID >= 0)
                    {
                        var faction = _factions.LookupByKey((uint)factionEntry.reputationListID);

                        // update standing to current
                        faction.Standing = result.Read <int>(i, 1);

                        // update counters
                        int            BaseRep  = GetBaseReputation(factionEntry);
                        ReputationRank old_rank = ReputationToRank(BaseRep);
                        ReputationRank new_rank = ReputationToRank(BaseRep + faction.Standing);
                        UpdateRankCounters(old_rank, new_rank);

                        FactionFlags dbFactionFlags = (FactionFlags)result.Read <uint>(i, 2);

                        if (Convert.ToBoolean(dbFactionFlags & FactionFlags.Visible))
                        {
                            SetVisible(faction);                    // have internal checks for forced invisibility
                        }
                        if (Convert.ToBoolean(dbFactionFlags & FactionFlags.Inactive))
                        {
                            SetInactive(faction, true);                             // have internal checks for visibility requirement
                        }
                        if (Convert.ToBoolean(dbFactionFlags & FactionFlags.AtWar)) // DB at war
                        {
                            SetAtWar(faction, true);                                // have internal checks for FACTION_FLAG_PEACE_FORCED
                        }
                        else                                                        // DB not at war
                        {
                            // allow remove if visible (and then not FACTION_FLAG_INVISIBLE_FORCED or FACTION_FLAG_HIDDEN)
                            if (Convert.ToBoolean(faction.Flags & FactionFlags.Visible))
                            {
                                SetAtWar(faction, false);            // have internal checks for FACTION_FLAG_PEACE_FORCED
                            }
                        }

                        // set atWar for hostile
                        if (GetRank(factionEntry) <= ReputationRank.Hostile)
                        {
                            SetAtWar(faction, true);
                        }

                        // reset changed flag if values similar to saved in DB
                        if (faction.Flags == dbFactionFlags)
                        {
                            faction.needSend = false;
                            faction.needSave = false;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void LoadFromDB(SQLResult result)
        {
            // Set initial reputations (so everything is nifty before DB data load)
            Initialize();

            if (!result.IsEmpty())
            {
                do
                {
                    var factionEntry = CliDB.FactionStorage.LookupByKey(result.Read <uint>(0));
                    if (factionEntry != null && factionEntry.CanHaveReputation())
                    {
                        var faction = _factions.LookupByKey((uint)factionEntry.ReputationIndex);
                        if (faction == null)
                        {
                            continue;
                        }
                        // update standing to current
                        faction.Standing = result.Read <int>(1);

                        // update counters
                        int            BaseRep  = GetBaseReputation(factionEntry);
                        ReputationRank old_rank = ReputationToRank(BaseRep);
                        ReputationRank new_rank = ReputationToRank(BaseRep + faction.Standing);
                        UpdateRankCounters(old_rank, new_rank);

                        FactionFlags dbFactionFlags = (FactionFlags)result.Read <uint>(2);

                        if (Convert.ToBoolean(dbFactionFlags & FactionFlags.Visible))
                        {
                            SetVisible(faction);                    // have internal checks for forced invisibility
                        }
                        if (Convert.ToBoolean(dbFactionFlags & FactionFlags.Inactive))
                        {
                            SetInactive(faction, true);                             // have internal checks for visibility requirement
                        }
                        if (Convert.ToBoolean(dbFactionFlags & FactionFlags.AtWar)) // DB at war
                        {
                            SetAtWar(faction, true);                                // have internal checks for FACTION_FLAG_PEACE_FORCED
                        }
                        else                                                        // DB not at war
                        {
                            // allow remove if visible (and then not FACTION_FLAG_INVISIBLE_FORCED or FACTION_FLAG_HIDDEN)
                            if (Convert.ToBoolean(faction.Flags & FactionFlags.Visible))
                            {
                                SetAtWar(faction, false);            // have internal checks for FACTION_FLAG_PEACE_FORCED
                            }
                        }

                        // set atWar for hostile
                        if (GetRank(factionEntry) <= ReputationRank.Hostile)
                        {
                            SetAtWar(faction, true);
                        }

                        // reset changed flag if values similar to saved in DB
                        if (faction.Flags == dbFactionFlags)
                        {
                            faction.needSend = false;
                            faction.needSave = false;
                        }
                    }
                } while (result.NextRow());
            }
        }
Ejemplo n.º 5
0
        static bool HandleCharacterReputationCommand(StringArguments args, CommandHandler handler)
        {
            Player target;

            if (!handler.ExtractPlayerTarget(args, out target))
            {
                return(false);
            }

            Locale loc = handler.GetSessionDbcLocale();

            var targetFSL = target.GetReputationMgr().GetStateList();

            foreach (var pair in targetFSL)
            {
                FactionState   faction      = pair.Value;
                FactionRecord  factionEntry = CliDB.FactionStorage.LookupByKey(faction.Id);
                string         factionName  = factionEntry != null ? factionEntry.Name[loc] : "#Not found#";
                ReputationRank rank         = target.GetReputationMgr().GetRank(factionEntry);
                string         rankName     = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[(int)rank]);
                StringBuilder  ss           = new StringBuilder();
                if (handler.GetSession() != null)
                {
                    ss.AppendFormat("{0} - |cffffffff|Hfaction:{0}|h[{1} {2}]|h|r", faction.Id, factionName, loc);
                }
                else
                {
                    ss.AppendFormat("{0} - {1} {2}", faction.Id, factionName, loc);
                }

                ss.AppendFormat(" {0} ({1})", rankName, target.GetReputationMgr().GetReputation(factionEntry));

                if (faction.Flags.HasAnyFlag(FactionFlags.Visible))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionVisible));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.AtWar))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionAtwar));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.PeaceForced))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionPeaceForced));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.Hidden))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionHidden));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.InvisibleForced))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionInvisibleForced));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.Inactive))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionInactive));
                }

                handler.SendSysMessage(ss.ToString());
            }

            return(true);
        }
Ejemplo n.º 6
0
        public bool SetOneFactionReputation(FactionRecord factionEntry, int standing, bool incremental)
        {
            var factionState = _factions.LookupByKey((uint)factionEntry.ReputationIndex);

            if (factionState != null)
            {
                int BaseRep = GetBaseReputation(factionEntry);

                if (incremental)
                {
                    // int32 *= float cause one point loss?
                    standing  = (int)(Math.Floor(standing * WorldConfig.GetFloatValue(WorldCfg.RateReputationGain) + 0.5f));
                    standing += factionState.Standing + BaseRep;
                }

                if (standing > GetMaxReputation(factionEntry))
                {
                    standing = GetMaxReputation(factionEntry);
                }
                else if (standing < GetMinReputation(factionEntry))
                {
                    standing = GetMinReputation(factionEntry);
                }

                ReputationRank old_rank = ReputationToRank(factionEntry, factionState.Standing + BaseRep);
                ReputationRank new_rank = ReputationToRank(factionEntry, standing);

                int oldStanding = factionState.Standing + BaseRep;
                int newStanding = standing - BaseRep;

                _player.ReputationChanged(factionEntry, newStanding - factionState.Standing);

                factionState.Standing = newStanding;
                factionState.needSend = true;
                factionState.needSave = true;

                SetVisible(factionState);

                if (new_rank <= ReputationRank.Hostile)
                {
                    SetAtWar(factionState, true);
                }

                if (new_rank > old_rank)
                {
                    _sendFactionIncreased = true;
                }

                ParagonReputationRecord paragonReputation = Global.DB2Mgr.GetParagonReputation(factionEntry.Id);
                if (paragonReputation != null)
                {
                    int oldParagonLevel = oldStanding / paragonReputation.LevelThreshold;
                    int newParagonLevel = standing / paragonReputation.LevelThreshold;
                    if (oldParagonLevel != newParagonLevel)
                    {
                        Quest paragonRewardQuest = Global.ObjectMgr.GetQuestTemplate((uint)paragonReputation.QuestID);
                        if (paragonRewardQuest != null)
                        {
                            _player.AddQuestAndCheckCompletion(paragonRewardQuest, null);
                        }
                    }
                }

                if (factionEntry.FriendshipRepID == 0 && paragonReputation == null)
                {
                    UpdateRankCounters(old_rank, new_rank);
                }

                _player.UpdateCriteria(CriteriaType.TotalFactionsEncountered, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.ReputationGained, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.TotalExaltedFactions, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.TotalReveredFactions, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.TotalHonoredFactions, factionEntry.Id);

                return(true);
            }
            return(false);
        }