本文整理汇总了C#中TShockAPI.TSPlayer.SendData方法的典型用法代码示例。如果您正苦于以下问题:C# TSPlayer.SendData方法的具体用法?C# TSPlayer.SendData怎么用?C# TSPlayer.SendData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TShockAPI.TSPlayer
的用法示例。
在下文中一共展示了TSPlayer.SendData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNew
public int CreateNew(TSPlayer forPlayer, DPoint location, ItemData itemData, bool sendPacket = true)
{
int itemIndex = Item.NewItem(
location.X, location.Y, 0, 0, (int)itemData.Type, itemData.StackSize, true, (int)itemData.Prefix
);
if (sendPacket)
forPlayer.SendData(PacketTypes.ItemDrop, string.Empty, itemIndex);
return itemIndex;
}
示例2: HandleQuickStackNearby
public virtual bool HandleQuickStackNearby(TSPlayer player, int playerSlotIndex)
{
if (this.IsDisposed)
return false;
Item item = player.TPlayer.inventory[playerSlotIndex];
// TODO: fix this
//this.PutItemInNearbyChest(player, item, player.TPlayer.Center);
player.SendData(PacketTypes.PlayerSlot, string.Empty, player.Index, playerSlotIndex, item.prefix);
return true;
}
示例3: HandleChestUnlock
public virtual bool HandleChestUnlock(TSPlayer player, DPoint chestLocation)
{
if (this.IsDisposed)
return false;
ProtectionEntry protection = null;
// Only need the first enumerated entry as we don't need the protections of adjacent blocks.
foreach (ProtectionEntry enumProtection in this.ProtectionManager.EnumerateProtectionEntries(chestLocation)) {
protection = enumProtection;
break;
}
if (protection == null)
return false;
bool undoUnlock = false;
if (!this.ProtectionManager.CheckProtectionAccess(protection, player, false)) {
player.SendErrorMessage("This chest is protected, you can't unlock it.");
undoUnlock = true;
}
if (protection.RefillChestData != null && !this.CheckRefillChestLootability(protection.RefillChestData, player))
undoUnlock = true;
if (undoUnlock) {
bool dummy;
if (TerrariaUtils.Tiles.GetChestStyle(TerrariaUtils.Tiles[chestLocation], out dummy) == ChestStyle.GoldChest) {
int itemIndex = Item.NewItem(
chestLocation.X * TerrariaUtils.TileSize, chestLocation.Y * TerrariaUtils.TileSize, 0, 0, (int)ItemType.GoldenKey
);
player.SendData(PacketTypes.ItemDrop, string.Empty, itemIndex);
}
player.SendTileSquare(chestLocation, 3);
return true;
}
return false;
}
示例4: HandleChestRename
public virtual bool HandleChestRename(TSPlayer player, int chestIndex, string newName)
{
if (this.IsDisposed)
return false;
IChest chest = this.LastOpenedChest(player);
if (chest == null)
return true;
bool isAllowed = true;
if (this.CheckProtected(player, chest.Location, true)) {
player.SendErrorMessage("You have to be the owner of the chest in order to rename it.");
isAllowed = false;
}
if (this.Config.LoginRequiredForChestUsage && !player.IsLoggedIn) {
player.SendErrorMessage("You have to be logged in in order to rename chests.");
isAllowed = false;
}
if (!isAllowed) {
string originalName = string.Empty;
if (chest.IsWorldChest)
originalName = chest.Name;
// The name change will already have happened locally for the player, so gotta send the original name back to them.
player.SendData(PacketTypes.ChestName, originalName, chest.Index, chest.Location.X, chest.Location.Y);
return true;
} else {
// Only world chests can have names, so attempt to convert it into one.
if (!chest.IsWorldChest && !this.TrySwapChestData(null, chest.Location, out chest)) {
player.SendErrorMessage("The maximum amount of named chests for this world has been reached.");
return true;
}
chest.Name = newName;
player.SendData(PacketTypes.ChestName, chest.Name, chest.Index, chest.Location.X, chest.Location.Y);
return true;
}
}
示例5: HandleChestGetContents
//.........这里部分代码省略.........
ProtectionEntry protection = null;
// Only need the first enumerated entry as we don't need the protections of adjacent blocks.
foreach (ProtectionEntry enumProtection in this.ProtectionManager.EnumerateProtectionEntries(location)) {
protection = enumProtection;
break;
}
DPoint chestLocation = TerrariaUtils.Tiles.MeasureObject(location).OriginTileLocation;
IChest chest = this.ChestManager.ChestFromLocation(chestLocation, player);
if (chest == null)
return true;
if (this.IsChestInUse(player, chest)) {
player.SendErrorMessage("Another player is already viewing the content of this chest.");
return true;
}
if (protection != null) {
bool isTradeChest = (protection.TradeChestData != null);
if (!this.ProtectionManager.CheckProtectionAccess(protection, player)) {
if (isTradeChest)
this.InitTrade(player, chest, protection);
else
player.SendErrorMessage("This chest is protected.");
return true;
}
if (isTradeChest) {
Item sellItem = new Item();
sellItem.netDefaults(protection.TradeChestData.ItemToSellId);
sellItem.stack = protection.TradeChestData.ItemToSellAmount;
Item payItem = new Item();
payItem.netDefaults(protection.TradeChestData.ItemToPayId);
payItem.stack = protection.TradeChestData.ItemToPayAmount;
player.SendMessage($"This is a trade chest selling {TShock.Utils.ItemTag(sellItem)} for {TShock.Utils.ItemTag(payItem)}", Color.OrangeRed);
player.SendMessage("You have access to it, so you can modify it any time.", Color.LightGray);
}
if (protection.RefillChestData != null) {
RefillChestMetadata refillChest = protection.RefillChestData;
if (this.CheckRefillChestLootability(refillChest, player)) {
if (refillChest.OneLootPerPlayer)
player.SendMessage("You can loot this chest a single time only.", Color.OrangeRed);
} else {
return true;
}
if (refillChest.RefillTime != TimeSpan.Zero) {
lock (this.ChestManager.RefillTimers) {
if (this.ChestManager.RefillTimers.IsTimerRunning(refillChest.RefillTimer)) {
TimeSpan timeLeft = (refillChest.RefillStartTime + refillChest.RefillTime) - DateTime.Now;
player.SendMessage($"This chest will refill in {timeLeft.ToLongString()}.", Color.OrangeRed);
} else {
player.SendMessage("This chest will refill its content.", Color.OrangeRed);
}
}
} else {
player.SendMessage("This chest will refill its content.", Color.OrangeRed);
}
}
}
lock (ChestManager.DummyChest) {
Main.chest[ChestManager.DummyChestIndex] = ChestManager.DummyChest;
if (chest.IsWorldChest) {
ChestManager.DummyChest.name = chest.Name;
player.TPlayer.chest = chest.Index;
} else {
player.TPlayer.chest = -1;
}
for (int i = 0; i < Chest.maxItems; i++) {
ChestManager.DummyChest.item[i] = chest.Items[i].ToItem();
player.SendData(PacketTypes.ChestItem, string.Empty, ChestManager.DummyChestIndex, i);
}
ChestManager.DummyChest.x = chestLocation.X;
ChestManager.DummyChest.y = chestLocation.Y;
player.SendData(PacketTypes.ChestOpen, string.Empty, ChestManager.DummyChestIndex);
ChestManager.DummyChest.x = 0;
}
DPoint oldChestLocation;
if (this.PlayerIndexChestDictionary.TryGetValue(player.Index, out oldChestLocation)) {
this.PlayerIndexChestDictionary.Remove(player.Index);
this.ChestPlayerIndexDictionary.Remove(oldChestLocation);
}
if (!chest.IsWorldChest) {
this.PlayerIndexChestDictionary[player.Index] = chestLocation;
this.ChestPlayerIndexDictionary[chestLocation] = player.Index;
}
return false;
}