Misc cleanups

This commit is contained in:
hondacrx
2017-07-22 10:56:15 -04:00
parent 54fc79fced
commit cbf11e07ae
14 changed files with 48 additions and 59 deletions
+1 -3
View File
@@ -285,9 +285,7 @@ namespace System
public static string ConvertFormatSyntax(this string str) public static string ConvertFormatSyntax(this string str)
{ {
// @"%(\d+(\.\d+)?)?(d|f|s|u|i|llX|X|ll)"; old working string pattern = @"(%\W*\d*[a-zA-Z]*)";
//@"%(\d+(\.\d+)?)?(-\d+[a-z]|[[a-z])"; working somewhat
string pattern = @"(%\W*\d*[a-zA-Z]*)"; //Working fully????
int count = 0; int count = 0;
string result = Regex.Replace(str, pattern, m => string result = Regex.Replace(str, pattern, m =>
+2 -2
View File
@@ -494,8 +494,8 @@ namespace Game.Chat
handler.HasLowerSecurityAccount(null, accountId, true)) handler.HasLowerSecurityAccount(null, accountId, true))
return false; return false;
int expansion = int.Parse(exp); //get int anyway (0 if error) byte expansion = byte.Parse(exp); //get int anyway (0 if error)
if (expansion < 0 || expansion > WorldConfig.GetIntValue(WorldCfg.Expansion)) if (expansion > WorldConfig.GetIntValue(WorldCfg.Expansion))
return false; return false;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPANSION); PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPANSION);
+3 -1
View File
@@ -55,9 +55,11 @@ namespace Game.Chat
string activeStr = target.GetUInt32Value(PlayerFields.ChosenTitle) == titleInfo.MaskID string activeStr = target.GetUInt32Value(PlayerFields.ChosenTitle) == titleInfo.MaskID
? handler.GetCypherString(CypherStrings.Active) : ""; ? handler.GetCypherString(CypherStrings.Active) : "";
string titleNameStr = string.Format(name.ConvertFormatSyntax(), targetName);
// send title in "id (idx:idx) - [namedlink locale]" format // send title in "id (idx:idx) - [namedlink locale]" format
if (handler.GetSession() != null) if (handler.GetSession() != null)
handler.SendSysMessage(CypherStrings.TitleListChat, titleInfo.Id, titleInfo.MaskID, titleInfo.Id, name, loc, knownStr, activeStr); handler.SendSysMessage(CypherStrings.TitleListChat, titleInfo.Id, titleInfo.MaskID, titleInfo.Id, titleNameStr, loc, knownStr, activeStr);
else else
handler.SendSysMessage(CypherStrings.TitleListConsole, titleInfo.Id, titleInfo.MaskID, name, loc, knownStr, activeStr); handler.SendSysMessage(CypherStrings.TitleListConsole, titleInfo.Id, titleInfo.MaskID, name, loc, knownStr, activeStr);
} }
+3 -3
View File
@@ -607,10 +607,10 @@ namespace Game.Chat
return false; return false;
} }
int currentValue = (int)handler.GetSession().GetPlayer().GetUInt32Value(opcode); uint currentValue = handler.GetSession().GetPlayer().GetUInt32Value(opcode);
currentValue += value; currentValue += (uint)value;
handler.GetSession().GetPlayer().SetUInt32Value(opcode, (uint)currentValue); handler.GetSession().GetPlayer().SetUInt32Value(opcode, currentValue);
handler.SendSysMessage(CypherStrings.Change32bitField, opcode, currentValue); handler.SendSysMessage(CypherStrings.Change32bitField, opcode, currentValue);
+1 -1
View File
@@ -829,7 +829,7 @@ namespace Game.Chat
string activeStr = target && target.GetUInt32Value(PlayerFields.ChosenTitle) == titleInfo.MaskID string activeStr = target && target.GetUInt32Value(PlayerFields.ChosenTitle) == titleInfo.MaskID
? handler.GetCypherString(CypherStrings.Active) : ""; ? handler.GetCypherString(CypherStrings.Active) : "";
string titleNameStr = name + targetName; string titleNameStr = string.Format(name.ConvertFormatSyntax(), targetName);
// send title in "id (idx:idx) - [namedlink locale]" format // send title in "id (idx:idx) - [namedlink locale]" format
if (handler.GetSession() != null) if (handler.GetSession() != null)
+1 -4
View File
@@ -110,11 +110,8 @@ namespace Game.Chat
} }
[Command("faction", RBACPermissions.CommandModifyFaction)] [Command("faction", RBACPermissions.CommandModifyFaction)]
static bool Faction(StringArguments args, CommandHandler handler) static bool HandleModifyFactionCommand(StringArguments args, CommandHandler handler)
{ {
if (args.Empty())
return false;
string pfactionid = handler.extractKeyFromLink(args, "Hfaction"); string pfactionid = handler.extractKeyFromLink(args, "Hfaction");
Creature target = handler.getSelectedCreature(); Creature target = handler.getSelectedCreature();
+10 -19
View File
@@ -957,7 +957,7 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
uint phaseGroupId = args.NextUInt32(); int phaseGroupId = args.NextInt32();
Creature creature = handler.getSelectedCreature(); Creature creature = handler.getSelectedCreature();
if (!creature || creature.IsPet()) if (!creature || creature.IsPet())
@@ -968,11 +968,11 @@ namespace Game.Chat
creature.ClearPhases(); creature.ClearPhases();
foreach (uint id in Global.DB2Mgr.GetPhasesForGroup(phaseGroupId)) foreach (uint id in Global.DB2Mgr.GetPhasesForGroup((uint)phaseGroupId))
creature.SetInPhase(id, false, true); // don't send update here for multiple phases, only send it once after adding all phases creature.SetInPhase(id, false, true); // don't send update here for multiple phases, only send it once after adding all phases
creature.UpdateObjectVisibility(); creature.UpdateObjectVisibility();
creature.SetDBPhase(-(int)phaseGroupId); creature.SetDBPhase(-phaseGroupId);
creature.SaveToDB(); creature.SaveToDB();
@@ -1030,28 +1030,20 @@ namespace Game.Chat
if (args.Empty()) if (args.Empty())
return false; return false;
int spawnTime = args.NextInt32(); uint spawnTime = args.NextUInt32();
if (spawnTime < 0)
{
handler.SendSysMessage(CypherStrings.BadValue);
return false;
}
Creature creature = handler.getSelectedCreature(); Creature creature = handler.getSelectedCreature();
ulong guidLow = 0; if (!creature)
if (creature)
guidLow = creature.GetSpawnId();
else
return false; return false;
ulong guidLow = creature.GetSpawnId();
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_SPAWN_TIME_SECS); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_SPAWN_TIME_SECS);
stmt.AddValue(0, spawnTime); stmt.AddValue(0, spawnTime);
stmt.AddValue(1, guidLow); stmt.AddValue(1, guidLow);
DB.World.Execute(stmt); DB.World.Execute(stmt);
creature.SetRespawnDelay((uint)spawnTime); creature.SetRespawnDelay(spawnTime);
handler.SendSysMessage(CypherStrings.CommandSpawntime, spawnTime); handler.SendSysMessage(CypherStrings.CommandSpawntime, spawnTime);
return true; return true;
@@ -1167,11 +1159,10 @@ namespace Game.Chat
return false; return false;
} }
int item_int = int.Parse(pitem); uint itemId = uint.Parse(pitem);
if (item_int <= 0) if (itemId == 0)
return false; return false;
uint itemId = (uint)item_int;
uint maxcount = args.NextUInt32(); uint maxcount = args.NextUInt32();
uint incrtime = args.NextUInt32(); uint incrtime = args.NextUInt32();
uint extendedcost = args.NextUInt32(); uint extendedcost = args.NextUInt32();
+5 -5
View File
@@ -152,14 +152,14 @@ namespace Game.Chat
string maxPureSkill = args.NextString(); string maxPureSkill = args.NextString();
int skill = int.Parse(skillStr); uint skill = uint.Parse(skillStr);
if (skill <= 0) if (skill == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidSkillId, skill); handler.SendSysMessage(CypherStrings.InvalidSkillId, skill);
return false; return false;
} }
int level = int.Parse(levelStr); uint level = uint.Parse(levelStr);
Player target = handler.getSelectedPlayerOrSelf(); Player target = handler.getSelectedPlayerOrSelf();
if (!target) if (!target)
{ {
@@ -180,13 +180,13 @@ namespace Game.Chat
// the max level of the new profession. // the max level of the new profession.
ushort max = !string.IsNullOrEmpty(maxPureSkill) ? ushort.Parse(maxPureSkill) : targetHasSkill ? target.GetPureMaxSkillValue((SkillType)skill) : (ushort)level; ushort max = !string.IsNullOrEmpty(maxPureSkill) ? ushort.Parse(maxPureSkill) : targetHasSkill ? target.GetPureMaxSkillValue((SkillType)skill) : (ushort)level;
if (level <= 0 || level > max || max <= 0) if (level == 0 || level > max || max <= 0)
return false; return false;
// If the player has the skill, we get the current skill step. If they don't have the skill, we // If the player has the skill, we get the current skill step. If they don't have the skill, we
// add the skill to the player's book with step 1 (which is the first rank, in most cases something // add the skill to the player's book with step 1 (which is the first rank, in most cases something
// like 'Apprentice <skill>'. // like 'Apprentice <skill>'.
target.SetSkill((SkillType)skill, (uint)(targetHasSkill ? target.GetSkillStep((SkillType)skill) : 1), (uint)level, max); target.SetSkill((SkillType)skill, (uint)(targetHasSkill ? target.GetSkillStep((SkillType)skill) : 1), level, max);
handler.SendSysMessage(CypherStrings.SetSkill, skill, skillLine.DisplayName[handler.GetSessionDbcLocale()], handler.GetNameLink(target), level, max); handler.SendSysMessage(CypherStrings.SetSkill, skill, skillLine.DisplayName[handler.GetSessionDbcLocale()], handler.GetNameLink(target), level, max);
return true; return true;
} }
+1 -1
View File
@@ -278,7 +278,7 @@ namespace Game.Chat.Commands
Player player = handler.GetSession() != null ? handler.GetSession().GetPlayer() : null; Player player = handler.GetSession() != null ? handler.GetSession().GetPlayer() : null;
if (player && ticket.IsAssignedNotTo(player.GetGUID())) if (player && ticket.IsAssignedNotTo(player.GetGUID()))
{ {
handler.SendSysMessage(CypherStrings.CommandTicketalreadyassigned, ticket.GetId(), target); handler.SendSysMessage(CypherStrings.CommandTicketalreadyassigned, ticket.GetId());
return true; return true;
} }
+9 -8
View File
@@ -20,6 +20,7 @@ using Framework.IO;
using Game.DataStorage; using Game.DataStorage;
using Game.Entities; using Game.Entities;
using System.Collections.Generic; using System.Collections.Generic;
using System;
namespace Game.Chat.Commands namespace Game.Chat.Commands
{ {
@@ -34,8 +35,8 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id_p)) if (string.IsNullOrEmpty(id_p))
return false; return false;
int id = int.Parse(id_p); uint id = uint.Parse(id_p);
if (id <= 0) if (id == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidTitleId, id); handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
return false; return false;
@@ -76,8 +77,8 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id_p)) if (string.IsNullOrEmpty(id_p))
return false; return false;
int id = int.Parse(id_p); uint id = uint.Parse(id_p);
if (id <= 0) if (id == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidTitleId, id); handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
return false; return false;
@@ -103,7 +104,7 @@ namespace Game.Chat.Commands
string tNameLink = handler.GetNameLink(target); string tNameLink = handler.GetNameLink(target);
string titleNameStr = (target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()] + target.GetName(); string titleNameStr = string.Format((target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()].ConvertFormatSyntax(), target.GetName());
target.SetTitle(titleInfo); target.SetTitle(titleInfo);
handler.SendSysMessage(CypherStrings.TitleAddRes, id, titleNameStr, tNameLink); handler.SendSysMessage(CypherStrings.TitleAddRes, id, titleNameStr, tNameLink);
@@ -119,8 +120,8 @@ namespace Game.Chat.Commands
if (string.IsNullOrEmpty(id_p)) if (string.IsNullOrEmpty(id_p))
return false; return false;
int id = int.Parse(id_p); uint id = uint.Parse(id_p);
if (id <= 0) if (id == 0)
{ {
handler.SendSysMessage(CypherStrings.InvalidTitleId, id); handler.SendSysMessage(CypherStrings.InvalidTitleId, id);
return false; return false;
@@ -148,7 +149,7 @@ namespace Game.Chat.Commands
string tNameLink = handler.GetNameLink(target); string tNameLink = handler.GetNameLink(target);
string titleNameStr = (target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()] + target.GetName(); string titleNameStr = string.Format((target.GetGender() == Gender.Male ? titleInfo.NameMale : titleInfo.NameFemale)[handler.GetSessionDbcLocale()].ConvertFormatSyntax(), target.GetName());
handler.SendSysMessage(CypherStrings.TitleRemoveRes, id, titleNameStr, tNameLink); handler.SendSysMessage(CypherStrings.TitleRemoveRes, id, titleNameStr, tNameLink);
+3 -3
View File
@@ -227,7 +227,7 @@ namespace Game.Chat.Commands
if (id == 0) if (id == 0)
{ {
handler.SendSysMessage("|cffff33ffERROR: No vallid waypoint script id not present.|r"); handler.SendSysMessage("|cffff33ffERROR: No valid waypoint script id not present.|r");
return true; return true;
} }
@@ -256,7 +256,7 @@ namespace Game.Chat.Commands
if (arg_string == "setid") if (arg_string == "setid")
{ {
uint newid = uint.Parse(arg_3); uint newid = uint.Parse(arg_3);
handler.SendSysMessage("|cff00ff00Wp Event: Wypoint scipt guid: {0}|r|cff00ffff id changed: |r|cff00ff00{1}|r", newid, id); handler.SendSysMessage("|cff00ff00Wp Event: Waypoint script guid: {0}|r|cff00ffff id changed: |r|cff00ff00{1}|r", newid, id);
stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_ID); stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_SCRIPT_ID);
stmt.AddValue(0, newid); stmt.AddValue(0, newid);
@@ -774,7 +774,7 @@ namespace Game.Chat.Commands
if (show == "first") if (show == "first")
{ {
handler.SendSysMessage("|cff00ff00DEBUG: wp first, GUID: {0}|r", pathid); handler.SendSysMessage("|cff00ff00DEBUG: wp first, pathid: {0}|r", pathid);
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_FIRST_BY_ID); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_FIRST_BY_ID);
stmt.AddValue(0, pathid); stmt.AddValue(0, pathid);
+5 -5
View File
@@ -499,14 +499,14 @@ namespace Game.Entities
UpdatePolygonOrientation(); UpdatePolygonOrientation();
} }
bool UnitFitToActionRequirement(Unit unit, Unit caster, AreaTriggerActionUserTypes targetType) bool UnitFitToActionRequirement(Unit unit, Unit caster, AreaTriggerAction action)
{ {
switch (targetType) switch (action.TargetType)
{ {
case AreaTriggerActionUserTypes.Friend: case AreaTriggerActionUserTypes.Friend:
return caster.IsFriendlyTo(unit); return caster._IsValidAssistTarget(unit, Global.SpellMgr.GetSpellInfo(action.Param));
case AreaTriggerActionUserTypes.Enemy: case AreaTriggerActionUserTypes.Enemy:
return !caster.IsFriendlyTo(unit); return caster._IsValidAttackTarget(unit, Global.SpellMgr.GetSpellInfo(action.Param));
case AreaTriggerActionUserTypes.Raid: case AreaTriggerActionUserTypes.Raid:
return caster.IsInRaidWith(unit); return caster.IsInRaidWith(unit);
case AreaTriggerActionUserTypes.Party: case AreaTriggerActionUserTypes.Party:
@@ -528,7 +528,7 @@ namespace Game.Entities
{ {
foreach (AreaTriggerAction action in GetTemplate().Actions) foreach (AreaTriggerAction action in GetTemplate().Actions)
{ {
if (UnitFitToActionRequirement(unit, caster, action.TargetType)) if (UnitFitToActionRequirement(unit, caster, action))
{ {
switch (action.ActionType) switch (action.ActionType)
{ {
+1 -1
View File
@@ -229,7 +229,7 @@ namespace Game.Maps
instResetTime[instance] = Tuple.Create(pair.Item1, resettime); instResetTime[instance] = Tuple.Create(pair.Item1, resettime);
} }
} }
while (result.NextRow()); while (result2.NextRow());
} }
// schedule the reset times // schedule the reset times
+2 -2
View File
@@ -50,7 +50,7 @@ namespace Game.Scripting
InstanceMap instance = obj.GetMap().ToInstanceMap(); InstanceMap instance = obj.GetMap().ToInstanceMap();
if (instance != null && instance.GetInstanceScript() != null) if (instance != null && instance.GetInstanceScript() != null)
if (instance.GetScriptName() == scriptName) if (instance.GetScriptName() == scriptName)
return (T)Activator.CreateInstance(typeof(T), new object[] { obj }); return (T)Activator.CreateInstance(typeof(T), obj);
return null; return null;
} }
@@ -305,7 +305,7 @@ namespace Game.Scripting
if (me.GetInstanceScript() != null) if (me.GetInstanceScript() != null)
return GetInstanceAI<AI>(me); return GetInstanceAI<AI>(me);
else else
return (AI)Activator.CreateInstance(typeof(AI), me, _args); return (AI)Activator.CreateInstance(typeof(AI), new object[] { me }.Combine(_args));
} }
object[] _args; object[] _args;