本文整理汇总了C#中Server.MirObjects.PlayerObject.CanGainItem方法的典型用法代码示例。如果您正苦于以下问题:C# PlayerObject.CanGainItem方法的具体用法?C# PlayerObject.CanGainItem怎么用?C# PlayerObject.CanGainItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.MirObjects.PlayerObject
的用法示例。
在下文中一共展示了PlayerObject.CanGainItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Buy
public void Buy(PlayerObject player, ulong index, uint count)
{
UserItem goods = null;
for (int i = 0; i < Goods.Count; i++)
{
if (Goods[i].UniqueID != index) continue;
goods = Goods[i];
break;
}
bool isUsed = false;
if (goods == null)
{
for (int i = 0; i < UsedGoods.Count; i++)
{
if (UsedGoods[i].UniqueID != index) continue;
goods = UsedGoods[i];
isUsed = true;
break;
}
}
bool isBuyBack = false;
if (goods == null)
{
if (!BuyBack.ContainsKey(player.Name)) BuyBack[player.Name] = new List<UserItem>();
for (int i = 0; i < BuyBack[player.Name].Count; i++)
{
if (BuyBack[player.Name][i].UniqueID != index) continue;
goods = BuyBack[player.Name][i];
isBuyBack = true;
break;
}
}
if (goods == null || goods.Count == 0 || goods.Count > goods.Info.StackSize) return;
uint cost = goods.Price();
cost = (uint)(cost * Info.PriceRate);
if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
{
if (cost > player.Info.PearlCount) return;
}
else if (cost > player.Account.Gold) return;
UserItem item = (isBuyBack || isUsed ? goods : Envir.CreateFreshItem(goods.Info));
item.Count = goods.Count;
if (!player.CanGainItem(item)) return;
if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
{
player.Info.PearlCount -= (int)cost;
}
else
{
player.Account.Gold -= cost;
player.Enqueue(new S.LoseGold { Gold = cost });
}
player.GainItem(item);
if (isUsed)
{
UsedGoods.Remove(goods);
List<UserItem> newGoodsList = new List<UserItem>();
newGoodsList.AddRange(Goods);
newGoodsList.AddRange(UsedGoods);
NeedSave = true;
player.Enqueue(new S.NPCGoods { List = newGoodsList, Rate = Info.PriceRate });
}
if (isBuyBack)
{
BuyBack[player.Name].Remove(goods);
player.Enqueue(new S.NPCGoods { List = BuyBack[player.Name], Rate = Info.PriceRate });
}
}
示例2: Buy
public void Buy(PlayerObject player, ulong index, uint count)
{
UserItem goods = null;
for (int i = 0; i < Goods.Count; i++)
{
if (Goods[i].UniqueID != index) continue;
goods = Goods[i];
break;
}
bool isUsed = false;
if (goods == null)
{
for (int i = 0; i < UsedGoods.Count; i++)
{
if (UsedGoods[i].UniqueID != index) continue;
goods = UsedGoods[i];
isUsed = true;
break;
}
}
bool isBuyBack = false;
if (goods == null)
{
if (!BuyBack.ContainsKey(player.Name)) BuyBack[player.Name] = new List<UserItem>();
for (int i = 0; i < BuyBack[player.Name].Count; i++)
{
if (BuyBack[player.Name][i].UniqueID != index) continue;
goods = BuyBack[player.Name][i];
isBuyBack = true;
break;
}
}
if (goods == null || count == 0 || count > goods.Info.StackSize) return;
goods.Count = count;
uint cost = goods.Price();
cost = (uint)(cost * PriceRate(player));
uint baseCost = (uint)(goods.Price() * PriceRate(player, true));
if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
{
if (cost > player.Info.PearlCount) return;
}
else if (cost > player.Account.Gold) return;
UserItem item = (isBuyBack || isUsed) ? goods : Envir.CreateFreshItem(goods.Info);
item.Count = goods.Count;
if (!player.CanGainItem(item)) return;
if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
{
player.Info.PearlCount -= (int)cost;
}
else
{
player.Account.Gold -= cost;
player.Enqueue(new S.LoseGold { Gold = cost });
if (Conq != null) Conq.GoldStorage += (cost - baseCost);
}
player.GainItem(item);
if (isUsed)
{
UsedGoods.Remove(goods); //If used or buyback will destroy whole stack instead of reducing to remaining quantity
List<UserItem> newGoodsList = new List<UserItem>();
newGoodsList.AddRange(Goods);
newGoodsList.AddRange(UsedGoods);
NeedSave = true;
player.Enqueue(new S.NPCGoods { List = newGoodsList, Rate = PriceRate(player) });
}
if (isBuyBack)
{
BuyBack[player.Name].Remove(goods); //If used or buyback will destroy whole stack instead of reducing to remaining quantity
player.Enqueue(new S.NPCGoods { List = BuyBack[player.Name], Rate = PriceRate(player) });
}
}
示例3: Buy
public void Buy(PlayerObject player, int index, uint count)
{
ItemInfo info = null;
for (int i = 0; i < Goods.Count; i++)
{
if (Goods[i].Index != index) continue;
info = Goods[i];
break;
}
if (count == 0 || info == null || count > info.StackSize) return;
uint cost = info.Price*count;
cost = (uint) (cost*Info.PriceRate);
if (cost > player.Account.Gold) return;
UserItem item = Envir.CreateFreshItem(info);
item.Count = count;
if (!player.CanGainItem(item)) return;
player.Account.Gold -= cost;
player.Enqueue(new S.LoseGold {Gold = cost});
player.GainItem(item);
}
示例4: Act
private void Act(List<NPCActions> acts, PlayerObject player)
{
for (int i = 0; i < acts.Count; i++)
{
NPCActions act = acts[i];
uint gold;
uint count;
switch (act.Type)
{
case ActionType.Teleport:
Map temp = SMain.Envir.GetMap((int) act.Params[0]);
if (temp == null) return;
player.Teleport(temp, (Point) act.Params[1]);
break;
case ActionType.GiveGold:
gold = (uint)act.Params[0];
if (gold + player.Account.Gold >= uint.MaxValue)
gold = uint.MaxValue - player.Account.Gold;
player.GainGold(gold);
break;
case ActionType.TakeGold:
gold = (uint) act.Params[0];
if (gold >= player.Account.Gold) gold = player.Account.Gold;
player.Account.Gold -= gold;
player.Enqueue(new S.LoseGold { Gold = gold });
break;
case ActionType.GiveItem:
count = (uint)act.Params[1];
while (count > 0)
{
UserItem item = SMain.Envir.CreateFreshItem((ItemInfo)act.Params[0]);
if (item == null)
{
SMain.Enqueue(string.Format("Failed to create UserItem: {0}, Page: {1}", act.Params[0], Key));
return;
}
if (item.Info.StackSize > count)
{
item.Count = count;
count = 0;
}
else
{
count -= item.Info.StackSize;
item.Count = item.Info.StackSize;
}
if (player.CanGainItem(item, false))
player.GainItem(item);
}
break;
case ActionType.TakeItem:
ItemInfo info = (ItemInfo) act.Params[0];
count = (uint) act.Params[1];
for (int o = 0; o < player.Info.Inventory.Length; o++)
{
UserItem item = player.Info.Inventory[o];
if (item.Info != info) continue;
if (count > item.Count)
{
player.Enqueue(new S.DeleteItem {UniqueID = item.UniqueID, Count = item.Count});
player.Info.Inventory[o] = null;
count -= item.Count;
continue;
}
player.Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = count });
if (count == item.Count)
player.Info.Inventory[o] = null;
else
item.Count -= count;
break;
}
player.RefreshStats();
break;
}
}
}
示例5: Act
private void Act(IList<NPCActions> acts, PlayerObject player)
{
for (var i = 0; i < acts.Count; i++)
{
NPCActions act = acts[i];
uint gold;
uint count;
string path;
switch (act.Type)
{
case ActionType.Teleport:
var map = SMain.Envir.GetMapByNameAndInstance((string)act.Params[0]);
if (map == null) return;
var coords = (Point)act.Params[1];
if (coords.X > 0 && coords.Y > 0) player.Teleport(map, coords);
else player.TeleportRandom(200, 0, map);
break;
case ActionType.InstanceTeleport:
map = SMain.Envir.GetMapByNameAndInstance((string)act.Params[0], (int)act.Params[1]);
if (map == null) return;
player.Teleport(map, (Point)act.Params[2]);
break;
case ActionType.GiveGold:
gold = (uint)act.Params[0];
if (gold + player.Account.Gold >= uint.MaxValue)
gold = uint.MaxValue - player.Account.Gold;
player.GainGold(gold);
break;
case ActionType.TakeGold:
gold = (uint)act.Params[0];
if (gold >= player.Account.Gold) gold = player.Account.Gold;
player.Account.Gold -= gold;
player.Enqueue(new S.LoseGold { Gold = gold });
break;
case ActionType.GiveItem:
count = (uint)act.Params[1];
while (count > 0)
{
UserItem item = SMain.Envir.CreateFreshItem((ItemInfo)act.Params[0]);
if (item == null)
{
SMain.Enqueue(string.Format("Failed to create UserItem: {0}, Page: {1}", act.Params[0], Key));
return;
}
if (item.Info.StackSize > count)
{
item.Count = count;
count = 0;
}
else
{
count -= item.Info.StackSize;
item.Count = item.Info.StackSize;
}
if (player.CanGainItem(item, false))
player.GainItem(item);
}
break;
case ActionType.TakeItem:
ItemInfo info = (ItemInfo)act.Params[0];
count = (uint)act.Params[1];
for (int o = 0; o < player.Info.Inventory.Length; o++)
{
UserItem item = player.Info.Inventory[o];
if (item == null) continue;
if (item.Info != info) continue;
if (count > item.Count)
{
player.Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = item.Count });
player.Info.Inventory[o] = null;
count -= item.Count;
continue;
}
player.Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = count });
if (count == item.Count)
player.Info.Inventory[o] = null;
else
item.Count -= count;
break;
//.........这里部分代码省略.........