private void ChangeAbilityItemUI(int slot, AbilityItem item) { if (CheckForItemBar()) { item_bar.ability_slots[slot].sprite = item.menu_form; } }
public void setAbility(AbilityItem item) { current_ability=item.Ability; var u_stats=current_ability.GetComponent<UpgradeStats>(); grid_in.grid_height=u_stats.AvailableUpgrades.Length; clearGrid(); //creating sliders for(int i =0 ; i<u_stats.AvailableUpgrades.Length; i++){ var o=NGUITools.AddChild(UpgradeSliderGrid.gameObject, UpgradeSliderPrefab); var slider=o.GetComponent<UpgradeSliderScr>(); slider._camera=playerHud._Camera; slider.setStat(u_stats.AvailableUpgrades[i],item.Stats); } UpgradeSliderGrid.RepositionHard(); grid_in.UpdateGrid(); int gfx_offset=0; foreach(var g in grid_in.Grid){ g.transform.localPosition += new Vector3(52f+(gfx_offset*row_offset),0f,0f); gfx_offset++; } UpgradeSliderGrid.SkipStartReposition(); }
public void ChangeAbilityItem(int slot, string item_name) { if (slot < 4 && slot >= 0) { Debug.Log("Adding Ability Item " + slot); (AbilityItem aItem, int count) = ability_items.GetFirstOwnedItem(slot); if (count > 0) { if (slot == active_slot) { aItem.OnDestroy(); } ability_items.RevokeItem(aItem.name(), slot, true); } if (ability_items.RequestItem(item_name, slot, out aItem)) { ChangeAbilityItemUI(slot, aItem); } if (slot == active_slot) { Debug.Log("starting item"); ability_item = aItem; ability_item.Start(); } } }
public override bool Select(Character character) { if (!AllowAccess) { return(false); } if (item.Container != null) { return(false); } if (AccessOnlyWhenBroken) { if (item.Condition > 0) { return(false); } } if (AutoInteractWithContained && character.SelectedConstruction == null) { foreach (Item contained in Inventory.AllItems) { if (contained.TryInteract(character)) { character.FocusedItem = contained; return(false); } } } var abilityItem = new AbilityItem(item); character.CheckTalents(AbilityEffectType.OnOpenItemContainer, abilityItem); return(base.Select(character)); }
bool UseItem() { AbilityItem equippedItem = itemBar[equipIndex]; if (equippedItem.ItemType != AbilityItem.AbilityItemType.None) { int numLeft = equippedItem.Use(); switch (equippedItem.ItemType) { case AbilityItem.AbilityItemType.Crow: SpawnCrow(); break; case AbilityItem.AbilityItemType.Flare: Flare(); break; case AbilityItem.AbilityItemType.Bubble: SpawnBubble(); break; default: break; } if (numLeft == 0) { itemBar[equipIndex] = AbilityItem.NoneItem; numEquipped--; ShiftItem(1); } uiManager.UpdateItemBar(itemBar, equipIndex); return(true); } return(false); }
public bool PickupItem(AbilityItem.AbilityItemType type) { if (IncrementItem(type)) { Debug.Log("Slot 1 :" + itemBar[0].ItemType + ", " + itemBar[0].count + ". " + "Slot 2 :" + itemBar[1].ItemType + ", " + itemBar[1].count + ". " + "Slot 3 :" + itemBar[2].ItemType + ", " + itemBar[2].count + ". "); uiManager.UpdateItemBar(itemBar, equipIndex); return(true); } if (numEquipped < 3) { for (int i = 0; i < 3; i++) { if (itemBar[i].ItemType == AbilityItem.AbilityItemType.None) { itemBar[i] = new AbilityItem(type); numEquipped++; Debug.Log("Slot 1 :" + itemBar[0].ItemType + ", " + itemBar[0].count + ". " + "Slot 2 :" + itemBar[1].ItemType + ", " + itemBar[1].count + ". " + "Slot 3 :" + itemBar[2].ItemType + ", " + itemBar[2].count + ". "); uiManager.UpdateItemBar(itemBar, equipIndex); return(true); } } return(false); } else { //some UI output indicating inventory is full return(false); } }
public void setAbility(AbilityItem item) { current_ability = item.Ability; var u_stats = current_ability.GetComponent <UpgradeStats>(); grid_in.grid_height = u_stats.AvailableUpgrades.Length; clearGrid(); //creating sliders for (int i = 0; i < u_stats.AvailableUpgrades.Length; i++) { var o = NGUITools.AddChild(UpgradeSliderGrid.gameObject, UpgradeSliderPrefab); var slider = o.GetComponent <UpgradeSliderScr>(); slider._camera = playerHud._Camera; slider.setStat(u_stats.AvailableUpgrades[i], item.Stats); } UpgradeSliderGrid.RepositionHard(); grid_in.UpdateGrid(); int gfx_offset = 0; foreach (var g in grid_in.Grid) { g.transform.localPosition += new Vector3(52f + (gfx_offset * row_offset), 0f, 0f); gfx_offset++; } UpgradeSliderGrid.SkipStartReposition(); }
void AddItemToInventory(WorldItem request) { if (!IsOwner) { return; } Item shipped_item = ItemCatalogue.RequestItem(request.item_name); if (SharedItem.isSharedItem(shipped_item)) { if (!IsServer) { InvokeServerRpc(RPC_AddSharedItemNetwork, request.NetworkId, 1, channel: INVMANG_CHANNEL); } else { RPC_AddSharedItemNetwork(request.NetworkId, 1); } } else if (AbilityItem.isAbilityItem(shipped_item)) { shipped_item.context = this; shipped_item.menu_form = Resources.Load(shipped_item.name() + "MenuForm") as Sprite; actionSlots.ability_items[shipped_item.name()] = (AbilityItem)shipped_item; actionSlots.ChangeAbilityItem(actionSlots.ability_items.GetStackCount(), shipped_item.name()); } }
void AddItemToInventory(ItemRequest request) { if (!isOwner) { return; } Item shipped_item = amazon.RequestItem(request.item_name); if (SharedItem.isSharedItem(shipped_item)) { if (!isServer) { InvokeServerRpc(RPC_AddSharedItem, request.item_name, 1, channel: INVMANG_CHANNEL); } else { string item_name = request.item_name; uint clientId = NetworkingManager.singleton.LocalClientId; NetworkSharedItem netItem = new NetworkSharedItem(item_name); networkInv.AddItemStack(item_name, netItem, 1); } } if (AbilityItem.isAbilityItem(shipped_item)) { shipped_item.context = this; shipped_item.menu_form = image; actionSlots.ability_items[shipped_item.name()] = (AbilityItem)shipped_item; actionSlots.ChangeAbilityItem(actionSlots.ability_items.GetStackCount(), shipped_item.name()); } GameObject.Destroy(request.gameObject); }
public void AddTactic(Tactical tactic, AbilityItem abilityItem = null) { this.tactic = tactic; this.abilityItem = abilityItem ?? this.abilityItem; HandleTitle(); FitHeight(); }
public void GetItem(AbilityItem item) { this.abilityText.text = item.name; this.descriptionText.text = item.GetDescription(); this.instructionText.text = ControllerTextChanger.ReplaceText(item.instructions); this.abilityImage.sprite = item.detailedIcon; GlobalController.ShowAbilityGetUI(); }
public void OnDiff(BaseModelDiff.DiffAbilityItem diff) { bool flag = false; bool flag2 = false; if (Utility.IsExist(diff.add)) { int i = 0; for (int count = diff.add.Count; i < count; i++) { AbilityItem abilityItem = diff.add[i]; abilityItemInventory.Set(abilityItem.uniqId, abilityItem); if (GameSaveData.instance.AddNewItem(ITEM_ICON_TYPE.ABILITY_ITEM, abilityItem.uniqId)) { flag2 = true; } } flag = true; } if (Utility.IsExist(diff.update)) { int j = 0; for (int count2 = diff.update.Count; j < count2; j++) { AbilityItem abilityItem2 = diff.update[j]; abilityItemInventory.Set(abilityItem2.uniqId, abilityItem2); if (GameSaveData.instance.RemoveNewIcon(ITEM_ICON_TYPE.ABILITY_ITEM, abilityItem2.uniqId)) { flag2 = true; } } flag = true; } if (Utility.IsExist(diff.del)) { int k = 0; for (int count3 = diff.del.Count; k < count3; k++) { string text = diff.del[k]; abilityItemInventory.Delete(ulong.Parse(text)); if (GameSaveData.instance.RemoveNewIcon(ITEM_ICON_TYPE.ABILITY_ITEM, text)) { flag2 = true; } } flag = true; } if (flag2) { GameSaveData.Save(); } if (flag) { MonoBehaviourSingleton <GameSceneManager> .I.SetNotify(GameSection.NOTIFY_FLAG.UPDATE_ABILITY_ITEM_INVENTORY); } }
private static bool Prefix(AbilityItem __instance, int ___point, ref bool __result) { if (!enabled) { return(true); } __instance.SetPoint(___point + 1); __result = true; return(false); }
public IEnumerator UseAbility(AbilityItem abilityItem, Character target) { Ability ability = abilityItem.ability; GamePlay.instance.LockButs(); if (!ability.isPossibleUse(this, target)) { createPopup("WRONG TARGET"); } else { if (ability.PossibleTarget == PossibleTarget.Enemy) { Vector3 StartPos = transform.position; yield return(new WaitForSeconds(0.2f)); anim.SetBool("Run", true); yield return(StartCoroutine(MoveTo(target.transform.position, 1.5f))); anim.SetBool("Run", false); yield return(new WaitForSeconds(0.2f)); if (isEvil) { anim.SetTrigger("EnemyAttack"); } else { anim.SetTrigger("Attack"); } ability.AbilityUse(target); yield return(new WaitForSeconds(0.2f)); anim.SetBool("Run", true); yield return(StartCoroutine(MoveTo(StartPos, 0.001f))); anim.SetBool("Run", false); } if (ability.PossibleTarget == PossibleTarget.Ally) { yield return(new WaitForSeconds(0.2f)); anim.SetTrigger("Cast"); yield return(new WaitForSeconds(0.2f)); ability.AbilityUse(target); yield return(new WaitForSeconds(0.3f)); } abilitiesCooldown(); abilityItem.cooldown = ability.AbilityCooldown; GamePlay.instance.TURN(); } GamePlay.instance.UnlockButs(); }
// Use this for initialization void Awake() { if (buttonSpriteName == "none") { buttonSprite.gameObject.SetActive(false); } else { buttonSprite.spriteName = buttonSpriteName; } abilitySprite.spriteName = "empty"; abilityCooldownSprite.fillAmount = 0; Ability = new AbilityItem(); }
private void refreshAbilityData() { // 刷新插槽数据 Dictionary <int, AbilityData> abilityDic = AppContext.instance.customDataManager.abilityPoolDataDic; int index = 0; foreach (AbilityData itemData in abilityDic.Values) { AbilityItem abilityItem = this.abilityItemList[index]; abilityItem.gameObject.SetActive(true); abilityItem.init(itemData); index++; } }
public override void SetValue(EquipItem recv_data) { ulong.TryParse(recv_data.uniqId, out ulong result); base.uniqueID = result; base.tableID = (uint)recv_data.equipItemId; level = recv_data.level; exceed = recv_data.exceed; sellPrice = recv_data.price; isFavorite = (recv_data.is_locked != 0); UpdateTableData(); if (tableData == null) { Log.Error(LOG.RESOURCE, "table = null"); } else { exceedParam = tableData.GetExceedParam((uint)recv_data.exceed); if (exceedParam == null) { exceedParam = new EquipItemExceedParamTable.EquipItemExceedParamAll(); } int cnt = 0; int num = 0; if (exceedParam != null && exceedParam.ability.Length > 0) { num += exceedParam.ability.Length; } ability = new EquipItemAbility[recv_data.ability.Count + GetFixedAbilityCount() + num]; for (int i = 0; i < tableData.fixedAbility.Length; i++) { if (!tableData.fixedAbility[i].vr) { ability[++cnt] = new EquipItemAbility((uint)tableData.fixedAbility[i].id, tableData.fixedAbility[i].pt); } } recv_data.ability.ForEach(delegate(EquipItem.Ability a) { ability[++cnt] = new EquipItemAbility((uint)a.id, a.pt); }); if (num > 0) { for (int j = 0; j < num; j++) { ability[++cnt] = new EquipItemAbility((uint)exceedParam.ability[j].id, exceedParam.ability[j].pt); } } abilityItem = recv_data.abilityItem; } }
private void Start() { abilityDisplayArea = AbilityDisplayArea.instance; terminalAbility = LootWrangler.instance.GetRandomAbility(); abilityDisplayArea.SetNewItemSlot(terminalAbility.ability); if (terminalAbility.ability.abilityType == Ability.AbilityType.Mobility) { abilityDisplayArea.movementAbility = true; } else { abilityDisplayArea.movementAbility = false; } }
public AbilityContainer(PlayerMain player,AbilityItem ability) { cooldown=new Timer(1000,OnTimer,true); cooldown.Active=false; this.player=player; Ability=ability; ability_prefab=Ability.Ability; upgrade_stats=Ability.Stats; projectile_prefab=ability_prefab.GetComponent<AbilityStats>().ProjectilePrefab; ProStats = ability_prefab.GetComponent<ProjectileStats>(); sfx = ability_prefab.GetComponent<StoreSounds>(); }
public AbilityContainer(PlayerMain player, AbilityItem ability) { cooldown = new Timer(1000, OnTimer, true); cooldown.Active = false; this.player = player; Ability = ability; ability_prefab = Ability.Ability; upgrade_stats = Ability.Stats; projectile_prefab = ability_prefab.GetComponent <AbilityStats>().ProjectilePrefab; ProStats = ability_prefab.GetComponent <ProjectileStats>(); sfx = ability_prefab.GetComponent <StoreSounds>(); }
private static bool Prefix(AbilityItem __instance, ref string __result, AbilityData ___refData) { if (!enabled) { return(true); } string str = TextMgr.GetStr(___refData.descTextId, -1); List <object> list = new List <object>(); for (int i = 0; i < __instance.relatedModifierId.Count; i++) { list.AddRange(Module <FeatureModule> .Self.GetNextValueAry(__instance.relatedModifierId[i])); } __result = string.Format(str, list.ToArray()); return(false); }
private void loadAbilityItems() { // 加载能力插槽item int abilityCount = AppContext.instance.customDataManager.abilityPoolDataDic.Count; int startIndex = this.abilityItemList.Count; GameObject abilityItemPrefab = AppContext.instance.assetsManager.getAssetByUrlSync <GameObject> (CustomUrlString.abilityPrefab); for (int i = startIndex; i < abilityCount; i++) { GameObject abilityItemNode = ObjectPool.instance.requestInstance(abilityItemPrefab); abilityItemNode.transform.SetParent(this.abilityContent.transform, false); AbilityItem abilityItem = abilityItemNode.GetComponent <AbilityItem> (); this.abilityItemList.Add(abilityItem); } this.refreshAbilityData(); }
public void EquipAbilityItem(int abilitySlotIndex, AbilityItem abilityItem) { foreach (Ability ability in allAbilities) { if (abilityItem.ItemName == ability.abilityName) { if (abilityItem.ability.abilityType == Ability.AbilityType.Mobility) { ChangeMovementAbility(ability); } else { ChangeAbility(abilitySlotIndex, ability); } } } }
private void refreshAbilityState() { if (this.abilityItemList == null || this.abilityItemList.Count <= 0) { return; } for (int i = 0; i < this.abilityItemList.Count; i++) { AbilityItem abilityItem = this.abilityItemList[i]; if (abilityItem == null) { continue; } if (abilityItem.getJoinedState()) { ObjectPool.instance.returnInstance(abilityItem.gameObject); this.editorCardData.abilities.Add(abilityItem.AbilityData); this.editorCard.init(this.editorCardData); } } }
private static void Postfix(int group, int line, int icon, bool show, GameObject ___curLevelDetailParent, GameObject ___nextLevelDetailParent, ref PlayerAbilityDesc ___curLevelDetail, ref PlayerAbilityDesc ___nextLevelDetail, WhiteCat.Tween.Tweener[] ___levelChangeTween) { if (!enabled) { return; } AbilityItem abilityItem = Module <PlayerAbilityModule> .Self.Get(group, line, icon); if (show && abilityItem.IsMax) { ___curLevelDetailParent.gameObject.SetActive(true); foreach (WhiteCat.Tween.Tweener tweener2 in ___levelChangeTween) { tweener2.normalizedTime = 0f; tweener2.isForward = true; tweener2.enabled = true; } ___nextLevelDetailParent.gameObject.SetActive(true); ___curLevelDetail.SetDesc(abilityItem.GetIcon(), abilityItem.GetName(), abilityItem.Point, abilityItem.GetDesc()); ___nextLevelDetail.SetDesc(abilityItem.GetIcon(), abilityItem.GetName(), abilityItem.Point + 1, abilityItem.GetNextDesc()); } }
public override bool Use(float deltaTime, Character character = null) { tryingToCharge = true; if (character == null || character.Removed) { return(false); } if ((item.RequireAimToUse && !character.IsKeyDown(InputType.Aim)) || ReloadTimer > 0.0f) { return(false); } if (currentChargeTime < MaxChargeTime) { return(false); } IsActive = true; ReloadTimer = reload / (1 + character?.GetStatValue(StatTypes.RangedAttackSpeed) ?? 0f); currentChargeTime = 0f; if (character != null) { var abilityItem = new AbilityItem(item); character.CheckTalents(AbilityEffectType.OnUseRangedWeapon, abilityItem); } if (item.AiTarget != null) { item.AiTarget.SoundRange = item.AiTarget.MaxSoundRange; item.AiTarget.SightRange = item.AiTarget.MaxSightRange; } limbBodies.Clear(); foreach (Limb l in character.AnimController.Limbs) { if (l.IsSevered) { continue; } limbBodies.Add(l.body.FarseerBody); } float degreeOfFailure = 1.0f - DegreeOfSuccess(character); degreeOfFailure *= degreeOfFailure; if (degreeOfFailure > Rand.Range(0.0f, 1.0f)) { ApplyStatusEffects(ActionType.OnFailure, 1.0f, character); } for (int i = 0; i < ProjectileCount; i++) { Projectile projectile = FindProjectile(triggerOnUseOnContainers: true); if (projectile != null) { Vector2 barrelPos = TransformedBarrelPos + item.body.SimPosition; float rotation = (Item.body.Dir == 1.0f) ? Item.body.Rotation : Item.body.Rotation - MathHelper.Pi; float spread = GetSpread(character) * Rand.Range(-0.5f, 0.5f); var lastProjectile = LastProjectile; if (lastProjectile != projectile) { lastProjectile?.Item.GetComponent <Rope>()?.Snap(); } float damageMultiplier = 1f + item.GetQualityModifier(Quality.StatType.AttackMultiplier); projectile.Shoot(character, character.AnimController.AimSourceSimPos, barrelPos, rotation + spread, ignoredBodies: limbBodies.ToList(), createNetworkEvent: false, damageMultiplier); projectile.Item.GetComponent <Rope>()?.Attach(Item, projectile.Item); if (i == 0) { Item.body.ApplyLinearImpulse(new Vector2((float)Math.Cos(projectile.Item.body.Rotation), (float)Math.Sin(projectile.Item.body.Rotation)) * Item.body.Mass * -50.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); } projectile.Item.body.ApplyTorque(projectile.Item.body.Mass * degreeOfFailure * Rand.Range(-10.0f, 10.0f)); Item.RemoveContained(projectile.Item); } LastProjectile = projectile; } LaunchProjSpecific(); return(true); }
// Use this for initialization void Awake() { if(buttonSpriteName=="none") buttonSprite.gameObject.SetActive(false); else buttonSprite.spriteName=buttonSpriteName; abilitySprite.spriteName="empty"; abilityCooldownSprite.fillAmount=0; Ability=new AbilityItem(); }
public void TURN() { List <GameObject> temp = goodChars; for (int i = 0; i < temp.Count; i++) { GameObject charI = temp[i]; if (charI != null) { charI.GetComponent <Character>().Select(false); charI.GetComponent <Character>().Target(false); } else { goodChars.Remove(charI); } } temp = evilChars; for (int i = 0; i < temp.Count; i++) { GameObject charI = temp[i]; if (charI != null) { charI.GetComponent <Character>().Select(false); charI.GetComponent <Character>().Target(false); } else { evilChars.Remove(charI); } } if (evilChars.Count == 0) { GamePanel.SetActive(false); GameWinsPanel.SetActive(true); } if (goodChars.Count == 0) { GamePanel.SetActive(false); GameOverPanel.SetActive(true); } foreach (Transform child in AbilitiesPanel.transform) { Destroy(child.gameObject); } if (evilChars.Count > 0 && goodChars.Count > 0) { if (goodTurn) { goodTurn = false; goodCharsIndex += 1; if (goodCharsIndex > goodChars.Count - 1) { goodCharsIndex = 0; } GameObject character = goodChars[goodCharsIndex]; Attacker = character.GetComponent <Character>(); Attacker.Select(true); if (Attacker.CheckCharacter()) { Target = evilChars[0].GetComponent <Character>(); Target.Target(true); foreach (AbilityItem item in Attacker.abilities) { Ability ability = item.ability; GameObject but = Instantiate(AbilityButtonPref, AbilitiesPanel.transform); but.GetComponent <AbilityButton>().SetText(ability.AbilityName); if (item.cooldown > 0) { but.GetComponent <AbilityButton>().SetCooldown(item.cooldown / ability.AbilityCooldown, item.cooldown); but.GetComponent <AbilityButton>().Disable(); } else { but.GetComponent <Button>().onClick.AddListener(() => { StartCoroutine(Attacker.UseAbility(item, this.Target)); }); } } } else { TURN(); } } else { goodTurn = true; evilCharsIndex += 1; if (evilCharsIndex > evilChars.Count - 1) { evilCharsIndex = 0; } GameObject character = evilChars[evilCharsIndex]; Attacker = character.GetComponent <Character>(); Attacker.Select(true); if (Attacker.CheckCharacter()) { //Выбор способности float allyCoef = 1f; for (int i = 0; i < evilChars.Count; i++) { GameObject charI = evilChars[i]; if (charI.GetComponent <Character>().health < 80) { allyCoef = 2f; } } AbilityItem UseAbility = Attacker.abilities[0]; float curCoeffecient = 0f; for (int i = 0; i < Attacker.abilities.Count; i++) { if (Attacker.abilities[i].cooldown == 0) { float AbCoef = Attacker.abilities[i].ability.AIweightCoefficient; if (Attacker.abilities[i].ability.PossibleTarget == PossibleTarget.Ally) { AbCoef = AbCoef * allyCoef; } if (AbCoef > curCoeffecient) { UseAbility = Attacker.abilities[i]; curCoeffecient = Attacker.abilities[i].ability.AIweightCoefficient; } } } //Выбор цели if (UseAbility.ability.PossibleTarget == PossibleTarget.Ally) { float minHP = 100f; bool choosed = false; for (int i = 0; i < evilChars.Count; i++) { GameObject charI = evilChars[i]; if (charI.GetComponent <Character>().health < minHP) { minHP = charI.GetComponent <Character>().health; Target = charI.GetComponent <Character>(); choosed = true; } } if (!choosed) { Target = evilChars[Random.Range(0, evilChars.Count)].GetComponent <Character>(); } } if (UseAbility.ability.PossibleTarget == PossibleTarget.Enemy) { float minHP = 100f; bool choosed = false; for (int i = 0; i < goodChars.Count; i++) { GameObject charI = goodChars[i]; if (charI.GetComponent <Character>().health < minHP) { minHP = charI.GetComponent <Character>().health; Target = charI.GetComponent <Character>(); choosed = true; } } if (!choosed) { Target = goodChars[Random.Range(0, goodChars.Count)].GetComponent <Character>(); } } Target.Target(true); //Применение StartCoroutine(Attacker.UseAbility(UseAbility, Target)); } else { TURN(); } } } }
private void ProcessItem(Item targetItem, IEnumerable <Item> inputItems, List <DeconstructItem> validDeconstructItems, bool allowRemove = true) { // In multiplayer, the server handles the deconstruction into new items if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; } if (user != null && !user.Removed) { var abilityTargetItem = new AbilityItem(targetItem); user.CheckTalents(AbilityEffectType.OnItemDeconstructed, abilityTargetItem); } if (targetItem.Prefab.RandomDeconstructionOutput) { int amount = targetItem.Prefab.RandomDeconstructionOutputAmount; List <int> deconstructItemIndexes = new List <int>(); for (int i = 0; i < validDeconstructItems.Count; i++) { deconstructItemIndexes.Add(i); } List <float> commonness = validDeconstructItems.Select(i => i.Commonness).ToList(); List <DeconstructItem> products = new List <DeconstructItem>(); for (int i = 0; i < amount; i++) { if (deconstructItemIndexes.Count < 1) { break; } var itemIndex = ToolBox.SelectWeightedRandom(deconstructItemIndexes, commonness, Rand.RandSync.Unsynced); products.Add(validDeconstructItems[itemIndex]); var removeIndex = deconstructItemIndexes.IndexOf(itemIndex); deconstructItemIndexes.RemoveAt(removeIndex); commonness.RemoveAt(removeIndex); } foreach (DeconstructItem deconstructProduct in products) { CreateDeconstructProduct(deconstructProduct, inputItems); } } else { foreach (DeconstructItem deconstructProduct in validDeconstructItems) { CreateDeconstructProduct(deconstructProduct, inputItems); } } void CreateDeconstructProduct(DeconstructItem deconstructProduct, IEnumerable <Item> inputItems) { float percentageHealth = targetItem.Condition / targetItem.MaxCondition; if (percentageHealth < deconstructProduct.MinCondition || percentageHealth > deconstructProduct.MaxCondition) { return; } if (!(MapEntityPrefab.Find(null, deconstructProduct.ItemIdentifier) is ItemPrefab itemPrefab)) { DebugConsole.ThrowError("Tried to deconstruct item \"" + targetItem.Name + "\" but couldn't find item prefab \"" + deconstructProduct.ItemIdentifier + "\"!"); return; } float condition = deconstructProduct.CopyCondition ? percentageHealth * itemPrefab.Health : itemPrefab.Health * Rand.Range(deconstructProduct.OutConditionMin, deconstructProduct.OutConditionMax); if (DeconstructItemsSimultaneously && deconstructProduct.RequiredOtherItem.Length > 0) { foreach (Item otherItem in inputItems) { if (targetItem == otherItem) { continue; } if (deconstructProduct.RequiredOtherItem.Any(r => otherItem.HasTag(r) || r.Equals(otherItem.Prefab.Identifier, StringComparison.OrdinalIgnoreCase))) { user.CheckTalents(AbilityEffectType.OnGeneticMaterialCombinedOrRefined); foreach (Character character in Character.GetFriendlyCrew(user)) { character.CheckTalents(AbilityEffectType.OnCrewGeneticMaterialCombinedOrRefined); } var geneticMaterial1 = targetItem.GetComponent <GeneticMaterial>(); var geneticMaterial2 = otherItem.GetComponent <GeneticMaterial>(); if (geneticMaterial1 != null && geneticMaterial2 != null) { if (geneticMaterial1.Combine(geneticMaterial2, user)) { inputContainer.Inventory.RemoveItem(otherItem); OutputContainer.Inventory.RemoveItem(otherItem); Entity.Spawner.AddToRemoveQueue(otherItem); } allowRemove = false; return; } inputContainer.Inventory.RemoveItem(otherItem); OutputContainer.Inventory.RemoveItem(otherItem); Entity.Spawner.AddToRemoveQueue(otherItem); } } } int amount = 1; if (user != null && !user.Removed) { var itemsCreated = new AbilityValueItem(amount, targetItem.Prefab); user.CheckTalents(AbilityEffectType.OnItemDeconstructedMaterial, itemsCreated); amount = (int)itemsCreated.Value; // used to spawn items directly into the deconstructor var itemContainer = new AbilityItemPrefabItem(item, targetItem.Prefab); user.CheckTalents(AbilityEffectType.OnItemDeconstructedInventory, itemContainer); } for (int i = 0; i < amount; i++) { Entity.Spawner.AddToSpawnQueue(itemPrefab, outputContainer.Inventory, condition, onSpawned: (Item spawnedItem) => { for (int i = 0; i < outputContainer.Capacity; i++) { var containedItem = outputContainer.Inventory.GetItemAt(i); if (containedItem?.Combine(spawnedItem, null) ?? false) { break; } } PutItemsToLinkedContainer(); }); } } if (targetItem.AllowDeconstruct && allowRemove) { //drop all items that are inside the deconstructed item foreach (ItemContainer ic in targetItem.GetComponents <ItemContainer>()) { if (ic?.Inventory == null || ic.RemoveContainedItemsOnDeconstruct) { continue; } ic.Inventory.AllItemsMod.ForEach(containedItem => outputContainer.Inventory.TryPutItem(containedItem, user: null)); } inputContainer.Inventory.RemoveItem(targetItem); Entity.Spawner.AddToRemoveQueue(targetItem); MoveInputQueue(); PutItemsToLinkedContainer(); } else { if (!outputContainer.Inventory.CanBePut(targetItem) || (Entity.Spawner?.IsInRemoveQueue(targetItem) ?? false)) { targetItem.Drop(dropper: null); } else { outputContainer.Inventory.TryPutItem(targetItem, user: null, createNetworkEvent: true); } } }
// Update is called once per frame void Update() { if (im.GetAbilitySlot1()) { if (ability_item != null) { ability_item.OnDestroy(); } active_slot = 0; (AbilityItem item, int item_count) = ability_items.GetFirstOwnedItem(active_slot); ability_item = item; if (ability_item != null) { ability_item.Start(); } UpdateSelectedSlotUI(active_slot); } else if (im.GetAbilitySlot2()) { if (ability_item != null) { ability_item.OnDestroy(); } active_slot = 1; (AbilityItem item, int item_count) = ability_items.GetFirstOwnedItem(active_slot); ability_item = item; if (ability_item != null) { ability_item.Start(); } UpdateSelectedSlotUI(active_slot); } else if (im.GetAbilitySlot3()) { if (ability_item != null) { ability_item.OnDestroy(); } active_slot = 2; (AbilityItem item, int item_count) = ability_items.GetFirstOwnedItem(active_slot); ability_item = item; if (ability_item != null) { ability_item.Start(); } UpdateSelectedSlotUI(active_slot); } else if (im.GetAbilitySlot4()) { if (ability_item != null) { ability_item.OnDestroy(); } active_slot = 3; (AbilityItem item, int item_count) = ability_items.GetFirstOwnedItem(active_slot); ability_item = item; if (ability_item != null) { ability_item.Start(); } UpdateSelectedSlotUI(active_slot); } if (shared_item != null) { shared_item.Update(); } if (ability_item != null) { ability_item.Update(); } }
private static void Postfix(GridPlayerAbility __instance, TextMeshProUGUI ___iconLevel, GameObject ___plusButton, Color ___notFullColor, GameObject ___lockIcon, WhiteCat.Tween.Tweener ___tweener, int ___group, int ___line, AbilityItem ___ability) { if (!enabled) { return; } int point = ___ability.Point; ___iconLevel.text = point.ToString(); ___iconLevel.color = ___notFullColor; bool flag2 = Module <PlayerAbilityModule> .Self.IsLocked(___group, ___line); bool flag3 = !flag2 && Module <PlayerAbilityModule> .Self.GetPoint() != 0; ___lockIcon.SetActive(flag2); if (!flag3) { __instance.selectableBg.OnDeselect(null); } __instance.GetComponentInChildren <GridEventHandler_NoDrag>().DisableClickEvent = !flag3; ___plusButton.SetActive(flag3); __instance.clickIcon.material.SetFloat("_Saturation", (float)((point != 0) ? 1 : 0)); ___tweener.normalizedTime = (float)((point != 0) ? 1 : 0); __instance.clickIcon.material.SetColor("_Color", (!flag2) ? Color.white : new Color(0.6f, 0.6f, 0.6f)); }