public void SetActiveSecondary(SecondaryItem swi) { for (int i = 0; i < secondaries.Count; i++) { secondaries[i].gameObject.SetActive(false); } ActiveSecondary = swi.secondary; ActiveSecondaryItem = swi; foreach (Secondary sw in secondaries) { if (sw.secondaryType == swi.secondary.secondaryType) { sw.gameObject.SetActive(true); MeshRenderer[] renderers = sw.gameObject.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer ren in renderers) { ren.enabled = sw.display; } if (sw.gameObject.GetComponent <MachineGunAuto>()) { sw.gameObject.GetComponent <MachineGunAuto>().enabled = sw.display; } break; } } }
private void btnUseItem_Click(object sender, EventArgs e) { SecondaryItem secondaryItem = ((SecondaryItem)cboSecondaryItem.SelectedItem); if (secondaryItem.isPotion == true) { // Get the currently selected potion from the combobox HealingPotion potion = (HealingPotion)cboSecondaryItem.SelectedItem; if (potion.MinLevel > _player.Level) { _player.RaiseMessage("You can't drink this potion."); _player.RaiseMessage("You need to be level " + potion.MinLevel + "."); return; } _player.UsePotion(potion); } else if (secondaryItem.isMagic == true) { DamageMagicScroll scroll = (DamageMagicScroll)secondaryItem; if (scroll.MinLevel > _player.Level) { _player.RaiseMessage("You can't cast this spell."); _player.RaiseMessage("You need to be level " + scroll.MinLevel + "."); return; } _player.UseScroll(scroll); } else { _player.RaiseMessage("Bug: This item isn't an item type at all!"); } }
public void ClearSLot() { secondaryItem = null; icon.sprite = null; icon.enabled = false; nbItem = 0; textNumber.enabled = false; }
public async Task Delete(SecondaryItem item) { // Example of validating: cascade deletes turned off, no deleting item that is in use by PrimaryEntity if (await _unitOfWork.PrimaryItems.Any(x => x.SecondaryItemId == item.Id)) { throw new ArgumentInUseException(nameof(SecondaryItem.Id)); } _unitOfWork.SecondaryItems.Remove(item); await _unitOfWork.CommitAsync(); }
public void Remove(SecondaryItem weaponItem) { Debug.Log(weaponItem.amount); Destroy(weaponItem.secondary.gameObject); secondaries.Remove(weaponItem.secondary); secondaryItems.Remove(weaponItem); if (onItemChangedCallback != null) { onItemChangedCallback.Invoke(); } }
public async Task Update(SecondaryItem itemToUpdate, SecondaryItem item) { // Example of validating: Name is unique, we could catch exception too if (await _unitOfWork.SecondaryItems.SingleOrDefaultAsync(x => x.Name.Equals(item.Name) && x.Id != itemToUpdate.Id) != null) { throw new ArgumentNotUniqueException(nameof(SecondaryItem.Name)); } itemToUpdate.Name = item.Name; itemToUpdate.LastUpdated = DateTime.UtcNow; await _unitOfWork.CommitAsync(); }
public async Task <SecondaryItem> Create(SecondaryItem newItem) { // Example of validating: Name is unique, we could catch exception too if (await _unitOfWork.SecondaryItems.SingleOrDefaultAsync(x => x.Name.Equals(newItem.Name)) != null) { throw new ArgumentNotUniqueException(nameof(SecondaryItem.Name)); } newItem.LastUpdated = DateTime.UtcNow; await _unitOfWork.SecondaryItems.AddAsync(newItem); await _unitOfWork.CommitAsync(); return(newItem); }
public void AddItem(SecondaryItem newWeapon) { if (newWeapon.amount >= 0) { secondaryItem = new SecondaryItem(newWeapon.secondary, newWeapon.amount); secondary = secondaryItem.secondary; icon.sprite = secondaryItem.secondary.icon; icon.enabled = true; nbItem = newWeapon.amount; textNumber.enabled = true; textNumber.text = newWeapon.amount.ToString(); if (nbItem <= 0) { ClearSLot(); } } }
public void looseBullet() { foreach (SecondaryItem sw in secondaryItems) { if (sw.secondary.secondaryType == ActiveSecondaryItem.secondary.secondaryType) { sw.amount -= 1; onItemChangedCallback.Invoke(); if (sw.amount <= 0) { ActiveSecondaryItem = null; ActiveSecondary = null; } break; } } }
public bool Add(Secondary weapon, int amount) { foreach (SecondaryItem sp in secondaryItems) { if (sp.secondary.secondaryType == weapon.secondaryType) { //sp.weapon = weapon; sp.amount += amount; exist = true; break; } else { exist = false; } } if (!exist) { if (secondaryItems.Count >= Space) { Debug.Log("Not enough room in the inventory"); return(false); } SecondaryItem secondWeaponItem = new SecondaryItem(weapon, amount); GameObject goSecondWeapon = EquipWeapon(secondWeaponItem.secondary); secondWeaponItem.secondary = goSecondWeapon.GetComponent <Secondary>(); secondaryItems.Add(secondWeaponItem); if (onItemChangedCallback != null) { onItemChangedCallback.Invoke(); } } if (onItemChangedCallback != null) { onItemChangedCallback.Invoke(); } return(true); }
public void PickupSoul(SoulPickup soul) { switch (soul.Type) { case SoulPickup.SoulType.JUMP: C.Save.canJump = true; world.ui.UpdateHasJump(true); break; case SoulPickup.SoulType.SWORD: C.Save.canSword = true; selectedItem = SecondaryItem.SWORD; world.ui.UpdateSelectedItem(selectedItem); break; case SoulPickup.SoulType.BOW: C.Save.canBow = true; selectedItem = SecondaryItem.BOW; world.ui.UpdateSelectedItem(selectedItem); break; } }
public override void OnFixedUpdate() { swordCollision.SetPosition(this.GetPosition()); switch (_direction) { case Direction.RIGHT: swordCollision.hitBox.x = 6; swordCollision.hitBox.y = -8; swordCollision.hitBox.width = 15; swordCollision.hitBox.height = 12; break; case Direction.LEFT: swordCollision.hitBox.x = -6; swordCollision.hitBox.y = -8; swordCollision.hitBox.width = 15; swordCollision.hitBox.height = 12; break; case Direction.DOWN: swordCollision.hitBox.x = 0; swordCollision.hitBox.y = -12; swordCollision.hitBox.width = 12; swordCollision.hitBox.height = 15; break; case Direction.UP: swordCollision.hitBox.x = 0; swordCollision.hitBox.y = 8; swordCollision.hitBox.width = 12; swordCollision.hitBox.height = 15; break; } swordCollision.UpdateHitBoxSprite(); if (C.isTransitioning) return; switch (State) { case PlayerState.IDLE: case PlayerState.MOVE: maxXVel = 1f; maxYVel = 1; minYVel = -1f; if (State == PlayerState.MOVE) if (RXRandom.Float() < .04f) SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1); shouldDamage = false; if (C.getKey(C.JUMP_KEY) && CanJump && !world.checkForInteractObject(this)) { FSoundManager.PlaySound("jump"); State = PlayerState.JUMP; if (C.getKey(C.RIGHT_KEY)) _direction = Direction.RIGHT; else if (C.getKey(C.DOWN_KEY)) _direction = Direction.DOWN; else if (C.getKey(C.LEFT_KEY)) _direction = Direction.LEFT; else if (C.getKey(C.UP_KEY)) _direction = Direction.UP; Go.killAllTweensWithTarget(this); PlayAnim(true); SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length)); float newX = this.x; float newY = this.y; float targetY; float targetX; switch (_direction) { case Direction.UP: targetY = this.y + maxJumpDist; while (newY < targetY && !(world.CheckForJumpObjectCollisionHitbox(this, this.x, newY) != null)) newY += 1; while (newY > this.y && (!world.isAllPassable(this, this.x , newY, false) || world.CheckObjectCollisionHitbox(this, this.x, newY) != null)) { newY -= 1f; } break; case Direction.RIGHT: targetX = this.x + maxJumpDist; while (newX < targetX && !(world.CheckForJumpObjectCollisionHitbox(this, newX, this.y) != null)) newX += 1; while (newX > this.x && (!world.isAllPassable(this,newX , this.y, true) || world.CheckObjectCollisionHitbox(this, newX, this.y) != null)) { newX -= 1f; } break; case Direction.DOWN: targetY = this.y - maxJumpDist; while (newY > targetY && !(world.CheckForJumpObjectCollisionHitbox(this, this.x, newY) != null)) newY -= 1; while (newY < this.y && (!world.isAllPassable(this, this.x , newY, false) || world.CheckObjectCollisionHitbox(this, this.x, newY) != null)) { newY += 1f; } break; case Direction.LEFT: targetX = this.x - maxJumpDist; while (newX > targetX && !(world.CheckForJumpObjectCollisionHitbox(this, newX, this.y) != null)) newX -= 1; while (newX < this.x && (!world.isAllPassable(this, newX, this.y, true) || world.CheckObjectCollisionHitbox(this, newX, this.y) != null)) { newX += 1f; } break; } xVel = 0; yVel = 0; float jumpTime = .5f; float jumpDisp = 10f; if (_direction == Direction.UP || _direction == Direction.DOWN) { Go.to(this, jumpTime / 2f, new TweenConfig().floatProp("x", -jumpDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong)); Go.to(this, jumpTime, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.QuadOut).onComplete(() => { yVel = .01f; State = PlayerState.IDLE; })); } else { Go.to(this, jumpTime / 2f, new TweenConfig().floatProp("y", jumpDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong)); Go.to(this, jumpTime, new TweenConfig().floatProp("x", newX).setEaseType(EaseType.QuadOut).onComplete(() => { yVel = .01f; State = PlayerState.IDLE; })); } if (_direction == Direction.RIGHT) scaleX = -1; else if (_direction == Direction.LEFT) scaleX = 1; return; } float attackTime = .4f; float attackDist = 16; float attackDisp = 3f; if (C.getKey(C.SELECT_KEY) && !lastSelectPress) { if (selectedItem == SecondaryItem.SWORD && C.Save.canBow) { FSoundManager.PlaySound("swap"); selectedItem = SecondaryItem.BOW; world.ui.UpdateSelectedItem(selectedItem); } else if (selectedItem == SecondaryItem.BOW && C.Save.canSword) { FSoundManager.PlaySound("swap"); selectedItem = SecondaryItem.SWORD; world.ui.UpdateSelectedItem(selectedItem); } } if (C.getKey(C.ACTION_KEY)) { hasSpawnedSpiritParticles = false; switch (selectedItem) { case SecondaryItem.SWORD: if (lastActionPress) break; FSoundManager.PlaySound("swordOne"); State = PlayerState.SWORD; if (C.getKey(C.RIGHT_KEY)) _direction = Direction.RIGHT; else if (C.getKey(C.DOWN_KEY)) _direction = Direction.DOWN; else if (C.getKey(C.LEFT_KEY)) _direction = Direction.LEFT; else if (C.getKey(C.UP_KEY)) _direction = Direction.UP; SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length)); Go.killAllTweensWithTarget(this); float newX = this.x; float newY = this.y; switch (_direction) { case Direction.UP: newY += attackDist; while (newY > this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null)) { newY -= 1f; } break; case Direction.RIGHT: newX += attackDist; while (newX > this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null)) { newX -= 1f; } break; case Direction.DOWN: newY -= attackDist; while (newY < this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null)) { newY += 1f; } break; case Direction.LEFT: newX -= attackDist; while (newX < this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null)) { newX += 1f; } break; } xVel = 0; yVel = 0; if (newX == this.x) { Go.to(this, attackTime / 2f, new TweenConfig().floatProp("x", -attackDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong)); Go.to(this, attackTime, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.BackInOut).onComplete(() => { })); } else { Go.to(this, attackTime / 2f, new TweenConfig().floatProp("y", attackDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong)); Go.to(this, attackTime, new TweenConfig().floatProp("x", newX).setEaseType(EaseType.BackInOut).onComplete(() => { })); } if (_direction == Direction.RIGHT) scaleX = -1; else if (_direction == Direction.LEFT) scaleX = 1; return; case SecondaryItem.BOW: SpawnDeathParticles(Direction.UP, 20); State = PlayerState.BOW_DRAWN; return; } } if (C.getKey(C.LEFT_KEY)) { xAcc = -moveSpeed; if (xVel > 0) { SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1); xVel *= .8f; } } else if (C.getKey(C.RIGHT_KEY)) { xAcc = moveSpeed; if (xVel < 0) { SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1); xVel *= .8f; } } else xVel *= .7f; if (C.getKey(C.UP_KEY)) { yAcc = moveSpeed; if (yVel < 0) { SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1); yVel *= .8f; } } else if (C.getKey(C.DOWN_KEY)) { yAcc = -moveSpeed; if (yVel > 0) { SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1); yVel *= .8f; } } else yVel *= .7f; break; case PlayerState.BOW_DRAWN: if (!C.getKey(C.ACTION_KEY)) { State = PlayerState.BOW_SHOOTING; Arrow arrow = new Arrow(this, world); arrow.SetDirection(CurrentDirection); arrow.PlayAnim(); arrow.SetPosition(this.GetPosition()); switch (CurrentDirection) { case Direction.UP: arrow.yVel = 2; break; case Direction.RIGHT: arrow.xVel = 2; break; case Direction.DOWN: arrow.yVel = -2; break; case Direction.LEFT: arrow.xVel = -2; break; } world.addObject(arrow); return; } float strafeSpeed = 5f; if (C.getKey(C.LEFT_KEY)) xVel = -strafeSpeed; else if (C.getKey(C.RIGHT_KEY)) xVel = strafeSpeed; else xVel *= .8f; if (C.getKey(C.UP_KEY)) yVel = strafeSpeed; else if (C.getKey(C.DOWN_KEY)) yVel = -strafeSpeed; else yVel *= .8f; break; case PlayerState.BOW_SHOOTING: xVel *= .8f; yVel *= .8f; if (stateCount > .5f) { State = PlayerState.IDLE; SpawnDeathParticles(Direction.UP, 20); } break; case PlayerState.SWORD: shouldDamage = stateCount > .2f && stateCount < .4f; if (stateCount > .6f) State = PlayerState.IDLE; else if (stateCount > .3f) { if (C.getKey(C.ACTION_KEY) && !lastActionPress) { float attack2Time = .25f; float attack2Dist = 20; float attack2Disp = 5f; State = PlayerState.SWORD_TWO; FSoundManager.PlaySound("swordTwo"); hasSpawnedSpiritParticles = false; if (C.getKey(C.RIGHT_KEY)) _direction = Direction.RIGHT; else if (C.getKey(C.DOWN_KEY)) _direction = Direction.DOWN; else if (C.getKey(C.LEFT_KEY)) _direction = Direction.LEFT; else if (C.getKey(C.UP_KEY)) _direction = Direction.UP; SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length)); Go.killAllTweensWithTarget(this); float newX = this.x; float newY = this.y; PlayAnim(true); switch (_direction) { case Direction.UP: newY += attack2Dist; while (newY > this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null)) { newY -= 1f; } break; case Direction.RIGHT: newX += attack2Dist; while (newX > this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null)) { newX -= 1f; } break; case Direction.DOWN: newY -= attack2Dist; while (newY < this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null)) { newY += 1f; } break; case Direction.LEFT: newX -= attack2Dist; while (newX < this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null)) { newX += 1f; } break; } xVel = 0; yVel = 0; Go.killAllTweensWithTarget(this); if (newX == this.x) { Go.to(this, attack2Time / 2f, new TweenConfig().floatProp("x", -attack2Disp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong)); Go.to(this, attack2Time, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.BackInOut).onComplete(() => { })); } else { Go.to(this, attack2Time / 2f, new TweenConfig().floatProp("y", attack2Disp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong)); Go.to(this, attack2Time, new TweenConfig().floatProp("x", newX).setEaseType(EaseType.BackInOut).onComplete(() => { })); } if (_direction == Direction.RIGHT) scaleX = -1; else if (_direction == Direction.LEFT) scaleX = 1; return; } } else if (stateCount > .25f) { if (!hasSpawnedSpiritParticles) { SpawnParticles(_direction); hasSpawnedSpiritParticles = true; } } break; case PlayerState.SWORD_TWO: shouldDamage = stateCount > .2f; if (stateCount > .6f) State = PlayerState.IDLE; else if (stateCount > .19f) if (!hasSpawnedSpiritParticles) { SpawnParticles(_direction, 30); hasSpawnedSpiritParticles = true; } break; case PlayerState.INVULNERABLE: if (RXRandom.Float() < .2f) SpawnParticles(Direction.UP, 1); this.isVisible = stateCount * 100 % 10 < 5; if (stateCount > invulnerableStunTime) { State = PlayerState.IDLE; maxXVel = 1; maxYVel = 1; minYVel = -1; this.isVisible = true; } this.xVel *= .9f; this.yVel *= .9f; break; case PlayerState.DYING: if (!hasSpawnedSpiritParticles) { if (RXRandom.Float() < .4f + .4f * stateCount) SpawnDeathParticles(Direction.UP, 1 + (int)stateCount); if (stateCount > invulnerableStunTime * 3) { FSoundManager.PlaySound("death"); C.getCameraInstance().shake(1.0f, .5f); SpawnDeathParticles(Direction.UP, 20); this.isVisible = false; hasSpawnedSpiritParticles = true; } else this.isVisible = stateCount * 100 % 10 < 5; } if (stateCount > invulnerableStunTime * 5) { world.Respawn(); maxXVel = 1; maxYVel = 1; minYVel = -1; } this.xVel *= .9f; this.yVel *= .9f; break; } if (xAcc != 0 || yAcc != 0) { switch (State) { case PlayerState.IDLE: { State = PlayerState.MOVE; } break; } } else { switch (State) { case PlayerState.MOVE: State = PlayerState.IDLE; break; } } base.OnFixedUpdate(); if (stateCount == 0 && State == PlayerState.MOVE) SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1); lastActionPress = C.getKey(C.ACTION_KEY); lastSelectPress = C.getKey(C.SELECT_KEY); lastJumpPress = C.getKey(C.JUMP_KEY); PlayAnim(); }
public void LoadLastSave() { C.Save.copy(C.lastSave); if (C.Save.canBow) selectedItem = SecondaryItem.BOW; else if (C.Save.canSword) selectedItem = SecondaryItem.SWORD; else selectedItem = SecondaryItem.NONE; world.ui.UpdateHasJump(C.Save.canJump); world.ui.UpdateSelectedItem(selectedItem); }