void OnMapLoaded() { if (identity == null) { identity = Instantiate(playerPrefab); foreach (var behaviour in identity.GetComponents <TickableBehaviour>()) { behaviour.enabled = false; } playerBehaviour = identity.GetComponent <Tickable>().AddBehaviour <PlayerBehaviour>(); identity.onSetPosition += OnPositionChange; } Tile startTile = map.GetRandomTileThatAllowsSpawn(); startTile.AddObject(identity); map.UpdateLighting(); map.Reveal(identity.x, identity.y, identity.viewDistance); mainCamera.GetComponent <PlayerCamera>().SetRotation(startTile.x, startTile.y, float.Epsilon, float.MaxValue); if (map.dungeonLevel == 1) { mainCamera.GetComponent <EntryAnimation>().isAnimating = true; } else { mainCamera.GetComponent <PlayerCamera>().SetY(identity.transform.position.y, 1, float.MaxValue); } }
// ================================================================================================== // // good for party, creature, chests and another things that can be only one of them in tile and can be move from there // or has a special interaction public void PutDungeonObjectInTile(DungeonObject obj, DungeonTile tile) { if (tile.IsBlockPath) { Debug.LogError(obj.gameObject.name + " cannot be placed at (" + tile.PosX + "," + tile.PosY + ")"); return; } obj.transform.position = tile.transform.position; obj.transform.parent = tile.transform; // if item, make it in ground state, so the sprite will change to icon if (obj.GetComponent <Item>() != null) { obj.GetComponent <Item>().State = ItemState.GROUND; } }
public void OnCollision(DungeonObject ob, bool isInstigator) { if (isInstigator) { return; } if (isLocked) { if (ob.GetComponent <Creature>()) { DungeonObject key; bool hasKey = ob.inventory.items.TryGetValue("Key", out key); if (hasKey) { key.quantity--; if (key.quantity == 0) { ob.inventory.items.Remove("Key"); } SetOpen(true); } } } else { if (Random.value * 2 > openDifficulty) { SetOpen(true); } } }
void OnPickedUpObject(DungeonObject ob) { if (ob.GetComponent <Weapon>() != null) { WeildRightHand(ob); } }
public void FinishAttack(DungeonObject dOb) { Creature creature = dOb.GetComponent <Creature>(); Weapon weapon = null; if (rightHandObject != null) { weapon = rightHandObject.GetComponent <Weapon>(); } if (attackWillHit && creature) { creature.baseObject.DamageFlash(1); // Got past armor / defense if (weapon == null) { creature.baseObject.TakeDamage(1); } else { int damage = UnityEngine.Random.Range(weapon.minBaseDamage, weapon.maxBaseDamage + 1); creature.baseObject.TakeDamage(damage); } } Vector3 originalPosition = baseObject.originalGlyphPosition; baseObject.glyphs.transform.localPosition = originalPosition; //tickable.nextActionTime = TimeManager.instance.time + (ulong)ticksPerAttack; }
public void Attack(Creature creature) { if (creature.x == map.width - 1 && x == 0) { lastDirectionAttackedOrMoved = Direction.LEFT; } else if (creature.x == 0 && x == map.width - 1) { lastDirectionAttackedOrMoved = Direction.RIGHT; } else if (creature.x < x) { lastDirectionAttackedOrMoved = Direction.LEFT; } else if (creature.x > x) { lastDirectionAttackedOrMoved = Direction.RIGHT; } else if (creature.y < y) { lastDirectionAttackedOrMoved = Direction.DOWN; } else if (creature.y > y) { lastDirectionAttackedOrMoved = Direction.UP; } Weapon weapon = null; if (rightHandObject != null) { weapon = rightHandObject.GetComponent <Weapon>(); } float roll = UnityEngine.Random.Range(0, 20); roll += dexterity; if (roll > creature.dexterity) { // Hit, but do we do damange? if (roll > creature.dexterity + creature.defense) { // Got past armor / defense if (weapon == null) { creature.TakeDamage(1); } else { int damage = UnityEngine.Random.Range(weapon.minBaseDamage, weapon.maxBaseDamage + 1); creature.TakeDamage(damage); } } } nextActionTime = TimeManager.time + (ulong)ticksPerAttack; AttackAnimation(); }
public void StartAttack(DungeonObject dOb) { Creature creature = dOb.GetComponent <Creature>(); if (dOb.x == map.width - 1 && x == 0) { lastDirectionAttackedOrMoved = Direction.LEFT; } else if (dOb.x == 0 && x == map.width - 1) { lastDirectionAttackedOrMoved = Direction.RIGHT; } else if (dOb.x < x) { lastDirectionAttackedOrMoved = Direction.LEFT; } else if (dOb.x > x) { lastDirectionAttackedOrMoved = Direction.RIGHT; } else if (dOb.y < y) { lastDirectionAttackedOrMoved = Direction.DOWN; } else if (dOb.y > y) { lastDirectionAttackedOrMoved = Direction.UP; } attackWillHit = false; if (creature != null) { float roll = UnityEngine.Random.Range(0, 20); roll += dexterity; if (roll > creature.dexterity) { // Hit, but do we do damange? if (roll > creature.dexterity + creature.defense) { // Got past armor / defense attackWillHit = true; } } } attackAnimationTime = 0; }
public bool ContinueAttack(DungeonObject dOb) { Creature creature = dOb.GetComponent <Creature>(); var glyph = baseObject.glyphs; if (!glyph) { return(true); } Vector3 originalPosition = baseObject.originalGlyphPosition; if (attackAnimationTime < attackAnimationDuration) { float offset = attackMovementAnimation.Evaluate(attackAnimationTime / attackAnimationDuration) * attackAnimationScale; switch (lastDirectionAttackedOrMoved) { case Direction.UP: glyph.transform.localPosition = originalPosition + Vector3.up * offset; break; case Direction.DOWN: glyph.transform.localPosition = originalPosition + Vector3.down * offset; break; case Direction.RIGHT: glyph.transform.localPosition = originalPosition + Vector3.right * offset; break; case Direction.LEFT: glyph.transform.localPosition = originalPosition + Vector3.left * offset; break; } if (attackWillHit && creature) { creature.baseObject.DamageFlash(attackAnimationTime / attackAnimationDuration); } attackAnimationTime += Time.deltaTime; return(false); } return(true); }