Skip to content

Commit 018bbe6

Browse files
authored
Merge pull request #138 from qq410525209/main
feat: add animation support for wings
2 parents 37b9ccd + 2f0bacb commit 018bbe6

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

Store/src/cs2-store.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Store;
1313
public class Store : BasePlugin, IPluginConfig<Item_Config>
1414
{
1515
public override string ModuleName => "Store";
16-
public override string ModuleVersion => "v18";
16+
public override string ModuleVersion => "v19";
1717
public override string ModuleAuthor => "schwarper";
1818

1919
public Item_Config Config { get; set; } = new();

Store/src/item/item.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ public static bool Equip(CCSPlayerController player, Dictionary<string, string>
167167
return false;
168168
}
169169

170-
// 根据物品类型采用不同的冲突检测逻辑
171170
List<Store_Equipment> currentItems = GetConflictingItems(player, item, itemType);
172171

173172
foreach (Store_Equipment currentItem in currentItems)
@@ -195,20 +194,15 @@ public static bool Equip(CCSPlayerController player, Dictionary<string, string>
195194
return true;
196195
}
197196

198-
/// <summary>
199-
/// 根据物品类型获取冲突的已装备物品
200-
/// </summary>
201197
private static List<Store_Equipment> GetConflictingItems(CCSPlayerController player, Dictionary<string, string> item, string itemType)
202198
{
203199
return itemType switch
204200
{
205-
// playerskin: 同类型且同slot的物品冲突(队伍限制)
206201
"playerskin" => [.. Instance.GlobalStorePlayerEquipments.FindAll(p =>
207202
p.SteamID == player.SteamID &&
208203
p.Type == itemType &&
209204
(p.Slot == int.Parse(item["slot"]) || (item["slot"] == "1" || p.Slot == 1)))],
210205

211-
// customweapon: 同武器类型的物品冲突(基于weapon属性,确保同一武器只能装备一个皮肤)
212206
"customweapon" => [.. Instance.GlobalStorePlayerEquipments.FindAll(p =>
213207
{
214208
if (p.SteamID != player.SteamID || p.Type != itemType)
@@ -221,13 +215,11 @@ private static List<Store_Equipment> GetConflictingItems(CCSPlayerController pla
221215
equippedWeapon == newWeapon;
222216
})],
223217

224-
// equipment: 同类型且同slot的物品冲突
225218
"equipment" => [.. Instance.GlobalStorePlayerEquipments.FindAll(p =>
226219
p.SteamID == player.SteamID &&
227220
p.Type == itemType &&
228221
p.Slot == int.Parse(item["slot"]))],
229222

230-
// 其他类型: 默认采用同类型且同slot冲突的逻辑
231223
_ => [.. Instance.GlobalStorePlayerEquipments.FindAll(p =>
232224
p.SteamID == player.SteamID &&
233225
p.Type == itemType &&

Store/src/item/items/wings.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public bool OnEquip(CCSPlayerController player, Dictionary<string, string> item)
4444
{
4545
if (!item.TryGetValue("slot", out var slotStr) || !int.TryParse(slotStr, out var slot) || slot < 0)
4646
return false;
47-
EquipWings(player, item["model"], slot);
47+
var animation = item.TryGetValue("animation", out var anim) ? anim : string.Empty;
48+
EquipWings(player, item["model"], slot, animation);
4849
return true;
4950
}
5051

@@ -56,12 +57,12 @@ public bool OnUnequip(CCSPlayerController player, Dictionary<string, string> ite
5657
return true;
5758
}
5859

59-
public static void EquipWings(CCSPlayerController player, string model, int slot)
60+
public static void EquipWings(CCSPlayerController player, string model, int slot, string animation = "")
6061
{
6162
UnEquipWings(player, slot);
6263
Server.NextFrame(() =>
6364
{
64-
var entity = CreateWings(player, model);
65+
var entity = CreateWings(player, model, animation);
6566
if (entity != null && entity.IsValid)
6667
{
6768
if (!PlayerWingsEntities.ContainsKey(player))
@@ -83,7 +84,7 @@ public static void UnEquipWings(CCSPlayerController player, int slot)
8384
PlayerWingsEntities.Remove(player);
8485
}
8586

86-
public static CDynamicProp? CreateWings(CCSPlayerController player, string model)
87+
public static CDynamicProp? CreateWings(CCSPlayerController player, string model, string animation = "")
8788
{
8889
var pawn = player.PlayerPawn.Value;
8990
if (pawn == null) return null;
@@ -93,6 +94,10 @@ public static void UnEquipWings(CCSPlayerController player, int slot)
9394
entity.SetModel(model);
9495
entity.DispatchSpawn();
9596
entity.AcceptInput("FollowEntity", pawn, pawn, "!activator");
97+
if (!string.IsNullOrEmpty(animation))
98+
{
99+
entity.AcceptInput("SetAnimation", value: animation);
100+
}
96101
var origin = pawn.AbsOrigin;
97102
if (origin != null)
98103
{
@@ -112,7 +117,8 @@ public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
112117
var item = Item.GetItem(equip.UniqueId);
113118
if (item != null && item.TryGetValue("model", out var model))
114119
{
115-
EquipWings(player, model, equip.Slot);
120+
var animation = item.TryGetValue("animation", out var anim) ? anim : string.Empty;
121+
EquipWings(player, model, equip.Slot, animation);
116122
}
117123
}
118124
return HookResult.Continue;

cs2-store-example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@
266266
"model": "models/hostage/hostage_carry.vmdl",
267267
"type": "wings",
268268
"price": "1000",
269-
"slot": "1"
269+
"slot": "1",
270+
"animation": ""
270271
}
271272
},
272273
"Tags": {

0 commit comments

Comments
 (0)