Merge pull request #90 from iamdroppy/useful-methods-player-manager

Useful methods player manager
This commit is contained in:
pr701 2023-01-23 23:10:43 +03:00 committed by GitHub
commit 4c80e59125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 11 deletions

View File

@ -28,12 +28,29 @@ namespace DiIiS_NA.LoginServer.Battle
OnlinePlayers.Add(client);
}
public static BattleClient GetClientbyCID(ulong cid)
public static BattleClient GetClientByCID(ulong cid)
{
foreach (var bc in OnlinePlayers)
if (bc.CID == cid)
return bc;
return null;
return OnlinePlayers.FirstOrDefault(bc => bc.CID == cid);
}
public static void SendWhisper(string message)
{
Broadcast(client =>
{
client.SendServerWhisper(message);
});
}
public static void Broadcast(Action<BattleClient> action, Func<BattleClient, bool> predicate)
{
foreach (var client in OnlinePlayers.Where(predicate))
action(client);
}
public static void Broadcast(Action<BattleClient> action)
{
foreach (var client in OnlinePlayers)
action(client);
}
public static void PlayerDisconnected(BattleClient client)

View File

@ -119,7 +119,6 @@ namespace DiIiS_NA.GameServer.CommandManager
var monster = player.World.SpawnMonster((ActorSno)actorSNO, position);
}
return $"Spawned {amount} mobs with ActorSNO: {actorSNO}";
}
@ -464,7 +463,6 @@ namespace DiIiS_NA.GameServer.CommandManager
var msg = new InventoryDropItemMessage { ItemID = item.DynamicID(player) };
player.Inventory.Consume(invokerClient.InGameClient, msg);
}
return $"Dropped {bpItems.Count} Items for you";
}
}
@ -696,6 +694,10 @@ namespace DiIiS_NA.GameServer.CommandManager
return String.Format("Message sended.");
}
return matches.Aggregate(matches.Count >= 1 ? "Actor Matches:\n" : "No match found.",
(current, match) => current +
$"[{match.SNOId.ToString("D6")}] {match.Name} ({(match.Data as DiIiS_NA.Core.MPQ.FileFormats.Actor).Type} {(((match.Data as DiIiS_NA.Core.MPQ.FileFormats.Actor).Type == ActorType.Gizmo) ? ((int)(match.Data as DiIiS_NA.Core.MPQ.FileFormats.Actor).TagMap[ActorKeys.GizmoGroup]).ToString() : "")})\n");
}
[CommandGroup("lookup",
@ -817,9 +819,10 @@ namespace DiIiS_NA.GameServer.CommandManager
}
}
return matches.Aggregate(matches.Count >= 1 ? "Power Matches:\n" : "No match found.",
(current, match) => current + $"[{match.SNOId.ToString("D6")}] {match.Name}\n");
}
return matches.Aggregate(matches.Count >= 1 ? "World Matches:\n" : "No match found.",
(current, match) => current +
$"[{match.SNOId.ToString("D6")}] {match.Name} - {(match.Data as World).DynamicWorld}\n");
}
[Command("world",
"Allows you to search for a world.\nUsage: lookup world <pattern> OR lookup world id <snoId>")]
@ -951,7 +954,7 @@ namespace DiIiS_NA.GameServer.CommandManager
public string Scene(string[] @params, BattleClient invokerClient)
{
var matches = new List<Asset>();
if (@params.Count() < 1)
return "Invalid arguments. Type 'help lookup scene' to get help.";