Rewrite trainer handling to properly support multiple trainers on the same creature

This commit is contained in:
hondacrx
2017-07-27 17:29:22 -04:00
parent 0d8729ae32
commit 0aa7df2f53
18 changed files with 434 additions and 508 deletions
+2
View File
@@ -140,6 +140,8 @@ namespace Game.Entities
RestMgr _restMgr;
uint _currentTrainerId;
//Combat
int[] baseRatingValue = new int[(int)CombatRating.Max];
public float[][] m_auraBaseMod = new float[(int)BaseModGroup.End][];
+7 -107
View File
@@ -1034,6 +1034,9 @@ namespace Game.Entities
public RestMgr GetRestMgr() { return _restMgr; }
public uint GetCurrentTrainerId() { return _currentTrainerId; }
public void SetCurrentTrainerId(uint trainerId) { _currentTrainerId = trainerId; }
public bool IsAdvancedCombatLoggingEnabled() { return _advancedCombatLoggingEnabled; }
public void SetAdvancedCombatLogging(bool enabled) { _advancedCombatLoggingEnabled = enabled; }
@@ -1093,26 +1096,6 @@ namespace Game.Entities
m_temporaryUnsummonedPetNumber = 0;
}
public void ResetPetTalents()
{
/* ODO: 6.x remove/update pet talents
// This needs another gossip option + NPC text as a confirmation.
// The confirmation gossip listid has the text: "Yes, please do."
Pet pet = GetPet();
if (!pet || pet.getPetType() != PetType.Hunter || pet.m_usedTalentCount == 0)
return;
CharmInfo charmInfo = pet.GetCharmInfo();
if (charmInfo == null)
{
Log.outError(LogFilter.Player, "Object (GUID: {0} TypeId: {1}) is considered pet-like but doesn't have a charminfo!", pet.GetGUID().ToString(), pet.GetTypeId());
return;
}
pet.resetTalents();
SendTalentsInfoData(true);
*/
}
public bool IsPetNeedBeTemporaryUnsummoned()
{
@@ -2352,10 +2335,10 @@ namespace Game.Entities
foreach (var menuItems in menuItemBounds)
{
bool canTalk = true;
if (!Global.ConditionMgr.IsObjectMeetToConditions(this, source, menuItems.Conditions))
continue;
bool canTalk = true;
GameObject go = source.ToGameObject();
Creature creature = source.ToCreature();
if (creature)
@@ -2384,11 +2367,7 @@ namespace Game.Entities
canTalk = false;
break;
case GossipOption.Unlearntalents:
if (!creature.isCanTrainingAndResetTalentsOf(this))
canTalk = false;
break;
case GossipOption.Unlearnpettalents:
if (GetPet() == null || GetPet().getPetType() != PetType.Hunter || GetPet().m_spells.Count <= 1 || creature.GetCreatureTemplate().TrainerType != TrainerType.Pets || creature.GetCreatureTemplate().TrainerClass != Class.Hunter)
if (!creature.CanResetTalents(this))
canTalk = false;
break;
case GossipOption.Taxivendor:
@@ -2407,11 +2386,6 @@ namespace Game.Entities
canTalk = false;
break;
case GossipOption.Trainer:
if (GetClass() != creature.GetCreatureTemplate().TrainerClass && creature.GetCreatureTemplate().TrainerType == TrainerType.Class)
Log.outError(LogFilter.Sql, "GOSSIP_OPTION_TRAINER. Player {0} (GUID: {1}) request wrong gossip menu: {2} with wrong class: {3} at Creature: {4} (Entry: {5}, Trainer Class: {6})",
GetName(), GetGUID().ToString(), menu.GetGossipMenu().GetMenuId(), GetClass(), creature.GetName(), creature.GetEntry(), creature.GetCreatureTemplate().TrainerClass);
canTalk = false;
break;
case GossipOption.Gossip:
case GossipOption.Spiritguide:
case GossipOption.Innkeeper:
@@ -2482,7 +2456,7 @@ namespace Game.Entities
}
menu.GetGossipMenu().AddMenuItem((int)menuItems.OptionIndex, menuItems.OptionIcon, strOptionText, 0, (uint)menuItems.OptionType, strBoxText, menuItems.BoxMoney, menuItems.BoxCoded);
menu.GetGossipMenu().AddGossipMenuItemData(menuItems.OptionIndex, menuItems.ActionMenuId, menuItems.ActionPoiId);
menu.GetGossipMenu().AddGossipMenuItemData(menuItems.OptionIndex, menuItems.ActionMenuId, menuItems.ActionPoiId, menuItems.TrainerId);
}
}
}
@@ -2580,7 +2554,7 @@ namespace Game.Entities
GetSession().SendStablePet(guid);
break;
case GossipOption.Trainer:
GetSession().SendTrainerList(guid);
GetSession().SendTrainerList(guid, menuItemData.TrainerId);
break;
case GossipOption.Learndualspec:
break;
@@ -2588,10 +2562,6 @@ namespace Game.Entities
PlayerTalkClass.SendCloseGossip();
SendRespecWipeConfirm(guid, GetNextResetTalentsCost());
break;
case GossipOption.Unlearnpettalents:
PlayerTalkClass.SendCloseGossip();
ResetPetTalents();
break;
case GossipOption.Taxivendor:
GetSession().SendTaxiMenu(source.ToCreature());
break;
@@ -5484,76 +5454,6 @@ namespace Game.Entities
return null;
}
public TrainerSpellState GetTrainerSpellState(TrainerSpell trainer_spell)
{
if (trainer_spell == null)
return TrainerSpellState.Red;
bool hasSpell = true;
for (var i = 0; i < SharedConst.MaxTrainerspellAbilityReqs; ++i)
{
if (trainer_spell.ReqAbility[i] == 0)
continue;
if (!HasSpell(trainer_spell.ReqAbility[i]))
{
hasSpell = false;
break;
}
}
// known spell
if (hasSpell)
return TrainerSpellState.Gray;
// check skill requirement
if (trainer_spell.ReqSkillLine != 0 && GetBaseSkillValue((SkillType)trainer_spell.ReqSkillLine) < trainer_spell.ReqSkillRank)
return TrainerSpellState.Red;
// check level requirement
if (getLevel() < trainer_spell.ReqLevel)
return TrainerSpellState.Red;
for (var i = 0; i < SharedConst.MaxTrainerspellAbilityReqs; ++i)
{
if (trainer_spell.ReqAbility[i] == 0)
continue;
// check race/class requirement
if (!IsSpellFitByClassAndRace(trainer_spell.ReqAbility[i]))
return TrainerSpellState.Red;
uint prevSpell = Global.SpellMgr.GetPrevSpellInChain(trainer_spell.ReqAbility[i]);
if (prevSpell != 0)
{
// check prev.rank requirement
if (!HasSpell(prevSpell))
return TrainerSpellState.Red;
}
var spellsRequired = Global.SpellMgr.GetSpellsRequiredForSpellBounds(trainer_spell.ReqAbility[i]);
foreach (var spellId in spellsRequired)
{
// check additional spell requirement
if (!HasSpell(spellId))
return TrainerSpellState.Red;
}
}
// check primary prof. limit
// first rank of primary profession spell when there are no proffesions avalible is disabled
for (var i = 0; i < SharedConst.MaxTrainerspellAbilityReqs; ++i)
{
if (trainer_spell.ReqAbility[i] == 0)
continue;
SpellInfo learnedSpellInfo = Global.SpellMgr.GetSpellInfo(trainer_spell.ReqAbility[i]);
if (learnedSpellInfo != null && learnedSpellInfo.IsPrimaryProfessionFirstRank() && (GetFreePrimaryProfessionPoints() == 0))
return TrainerSpellState.GreenDisabled;
}
return TrainerSpellState.Green;
}
public void SendInitialPacketsBeforeAddToMap()
{
if (!m_teleport_options.HasAnyFlag(TeleportToOptions.Seamless))