代码:
private void Executing(PlayerSession Player, string response, int code)
{
switch (code)
{
case 0:
Debug.LogError("Api does not responded to a request");
break;
case 200:
Dictionary<string, object> Response = JsonConvert.DeserializeObject<Dictionary<string, object>>(response, new KeyValuesConverter());
if (Response != null)
{
switch (Convert.ToInt32(Response["code"]))
{
case 100:
int i = 0;
List<object> data = Response["data"] as List<object>;
foreach (object pair in data)
{
if (i >= 14)
{
hurt.SendChatMessage(Player, $"Вы не можете получить больше 14 предметов за раз.");
return;
}
Dictionary<string, object> iteminfo = pair as Dictionary<string, object>;
if(iteminfo.ContainsKey("command"))
{
string command = iteminfo["command"].ToString().Replace('\n', '|').ToLower().Trim('\"').Replace("%steamid%", Player.SteamId.m_SteamID.ToString()).Replace("%username%", Player.Name);
String[] CommandArray = command.Split('|');
foreach (var substring in CommandArray)
{
ConsoleManager.Instance.ExecuteCommand(substring);
}
hurt.SendChatMessage(Player, $"Получен товар из магазина: <color=lime>\"{iteminfo["name"]}\"</color>.");
SendGived(new Dictionary<string, string>() { { "gived", "true" }, { "id", $"{iteminfo["id"]}" } }, Player);
return;
}
int ItemID = Convert.ToInt32(iteminfo["item_id"]);
int Amount = Convert.ToInt32(iteminfo["amount"]);
ItemInstance Item = new ItemInstance(GlobalItemManager.Instance.GetItem(ItemID), Amount);
if (Player.WorldPlayerEntity.GetComponent<Inventory>().GiveItemServer(Item))
{
Singleton<AlertManager>.Instance.GenericTextNotificationServer($"Получен товар из магазина: \"{iteminfo["name"]}\" в количестве {Amount}", session.Player);
} else {
hurt.SendChatMessage(Player, $"В инвентаре недостаточно места для получения <color=lime>\"{iteminfo["name"]}\"</color>");
return;
}
i++;
}
break;
case 104:
hurt.SendChatMessage(Player, $"Ваша корзина пуста!");
break;
}
}
else
Debug.LogWarning(response);
break;
case 404:
Debug.LogError("Response code: 404, please check your configurations");
break;
}
}
错误行
Singleton<AlertManager>.Instance.GenericTextNotificationServer($"Получен товар из магазина: \"{iteminfo["name"]}\" в количестве {Amount}", Player);
错误:
编译时出错:DASD.cs(109,195):错误CS1503:参数&#39;#2&#39;无法转换&#39; PlayerSession&#39;表达式以键入&u ;.www.NetworkPlayer&#39;
答案 0 :(得分:0)
方法Singleton<AlertManager>.Instance.GenericTextNotificationServer()
在其第二个参数中接受uLink.NetworkPlayer
类型的变量,您传递的类型为PlayerSession
。
所以显然你需要传递session
,而不是session.Player
。