You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.9 KiB
141 lines
4.9 KiB
namespace ET |
|
{ |
|
[FriendClass(typeof(Unit))] |
|
[FriendClass(typeof(Synthesis))] |
|
[FriendClass(typeof(Construct))] |
|
public static class StoreOperate |
|
{ |
|
public static void AddItem(Unit unit, int configId, long Amount) |
|
{ |
|
if (configId == 6001) |
|
{ |
|
// todo 最大值待定 |
|
if (unit.SilverTael + Amount > 99999999999) |
|
{ |
|
return; |
|
} |
|
unit.SilverTael += (int)Amount; |
|
return; |
|
} |
|
if (configId == 6002) |
|
{ |
|
// todo 最大值待定 |
|
if (unit.GoldIngot + Amount > 99999999999) |
|
{ |
|
return; |
|
} |
|
unit.GoldIngot += (int)Amount; |
|
return; |
|
} |
|
|
|
StoreComponent sc = unit.GetComponent<StoreComponent>(); |
|
sc.Add(configId, Amount); |
|
} |
|
|
|
public static int DropItem(Unit unit, int configId, int amount) |
|
{ |
|
StoreComponent store = unit.GetComponent<StoreComponent>(); |
|
|
|
var allItemConfig = AllItemConfigCategory.Instance.Get(configId); |
|
if (store.GetItemNum(configId) < amount || allItemConfig.AbleThrow == 0) |
|
{ |
|
return ErrorCode.ERR_DropError; |
|
} |
|
|
|
store.Remove(configId, amount); |
|
|
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
public static bool UseItem(Unit unit, int configId, int amount, long synthesisId) |
|
{ |
|
|
|
StoreComponent store = unit.GetComponent<StoreComponent>(); |
|
var allItemConfig = AllItemConfigCategory.Instance.Get(configId); |
|
if (store.GetItemNum(configId) < amount) |
|
{ |
|
return false; |
|
} |
|
|
|
switch (allItemConfig.RelatedTable) |
|
{ |
|
case 2: |
|
{ |
|
|
|
FunctionItemConfig fConfig = FunctionItemConfigCategory.Instance.Get(allItemConfig.RelatedId); |
|
switch (fConfig.UseType) |
|
{ |
|
case 1: |
|
{ |
|
|
|
} |
|
break; |
|
case 2: |
|
{ |
|
SynthesisComponent synthesisComponent = unit.GetComponent<SynthesisComponent>(); |
|
Synthesis synthesis = synthesisComponent.GetChild<Synthesis>(synthesisId); |
|
synthesis.Progress += fConfig.UseTypeParameter * amount * 60 * 1000; |
|
} |
|
break; |
|
case 3: |
|
{ |
|
MenuComponent menuComponent = unit.GetComponent<MenuComponent>(); |
|
menuComponent.initMenu(fConfig.UseTypeParameter); |
|
} |
|
break; |
|
case 4: |
|
{ |
|
ConstructComponent cc = unit.GetComponent<ConstructComponent>(); |
|
Construct construct = cc.GetChild<Construct>(synthesisId); |
|
construct.AddEfficiency += fConfig.UseTypeParameter * amount; |
|
} |
|
break; |
|
|
|
} |
|
} |
|
break; |
|
case 3: |
|
{ |
|
CuisineConfig cConfig = CuisineConfigCategory.Instance.Get(allItemConfig.RelatedId); |
|
if (cConfig != null) |
|
{ |
|
unit.Food += cConfig.FoodNum * amount; |
|
} |
|
} |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
store.Remove(configId, amount); |
|
return true; |
|
} |
|
|
|
public static ResourcePoint UseSaplingItem(Unit unit, int itemId, float posX, float posY) |
|
{ |
|
StoreComponent sc = unit.GetComponent<StoreComponent>(); |
|
if (sc.GetItemNum(itemId) < 1) |
|
{ |
|
return null; |
|
} |
|
|
|
if (sc.Remove(itemId, 1)) |
|
{ |
|
var itemConfig = AllItemConfigCategory.Instance.Get(itemId); |
|
FunctionItemConfig funcItemConfig = FunctionItemConfigCategory.Instance.Get(itemConfig.RelatedId); |
|
|
|
if (funcItemConfig.UseType != 1) |
|
{ |
|
return null; |
|
} |
|
|
|
var saplingConfigId = funcItemConfig.UseTypeParameter; |
|
var saplingConfig = SaplingConfigCategory.Instance.Get(saplingConfigId); |
|
|
|
return ResourceOperate.CreateResource(unit, saplingConfig.RelatedResourcesPoint, posX, posY); |
|
} |
|
|
|
return null; |
|
} |
|
} |
|
} |