예제 #1
0
        private Tile LoadChestTile(int floorNumber = 1, string assetName = "spr_floor")
        {
            floorNumber++;
            Tile      t     = LoadFloorTile("", assetName);
            Container chest = new Container("Sprites/Containers/chest2_closed", "Sprites/Containers/chest2_open", "Sounds/creaking-door-2", levelIndex);

            for (int x = 0; x < chest.IBox.Columns; x++)
            {
                for (int y = 0; y < chest.IBox.Rows; y++)
                {
                    int  i = x % 4;
                    int  spawnChance;
                    Item newItem;
                    switch (i)
                    {
                        #region cases
                    case 0:
                        spawnChance = 50;
                        newItem     = new Potion(floorNumber);
                        break;

                    case 1:
                        spawnChance = 30;
                        newItem     = new WeaponEquipment(floorNumber);
                        break;

                    case 2:
                        spawnChance = 30;
                        newItem     = new BodyEquipment(floorNumber, 3);
                        break;

                    case 3:
                        spawnChance = 30;
                        newItem     = new RingEquipment("empty:64:64:10:Gold");
                        break;

                    default:
                        throw new Exception("wtf");
                        #endregion
                    }
                    if (spawnChance > GameEnvironment.Random.Next(100))
                    {
                        ItemSlot cS = chest.IBox.Get(x, y) as ItemSlot;
                        cS.ChangeItem(newItem);
                    }
                }
            }
            t.PutOnTile(chest);
            return(t);
        }
        void InitContents(int floorNumber)
        {
            for (int x = 0; x < IBox.Columns; x++)
            {
                int  i = x % 4;
                int  spawnChance;
                Item newItem;
                switch (i)
                {
                    #region cases
                case 0:
                    spawnChance = 50;
                    newItem     = new Potion(floorNumber);
                    break;

                case 1:
                    spawnChance = 30;
                    newItem     = new WeaponEquipment(floorNumber);
                    break;

                case 2:
                    spawnChance = 30;
                    newItem     = new BodyEquipment(floorNumber, 3);
                    break;

                case 3:
                    spawnChance = 30;
                    newItem     = new RingEquipment("empty:64:64:10:Gold");
                    break;

                default:
                    throw new Exception("wtf");
                    #endregion
                }
                for (int y = 0; y < IBox.Rows; y++)
                {
                    if (spawnChance > GameEnvironment.Random.Next(100))
                    {
                        ItemSlot cS = IBox.Get(x, y) as ItemSlot;
                        cS.ChangeItem(newItem);
                    }
                }
            }
        }
        /// <summary>
        /// Handles attacking an opponent. First checks if attacker hits opponent, if succesfull sends attackvalue to defending side, if unsuccesfull displays miss feedback
        /// </summary>
        /// <param name="target"></param>
        public void Attack(Living target)
        {
            string     hitSound    = "Sounds/muted_metallic_crash_impact";
            int        damageDealt = 0;
            DamageType damageType  = DamageType.Physical;

            if (Weapon.SlotItem != null)
            {
                WeaponEquipment weaponItem = Weapon.SlotItem as WeaponEquipment;
                damageType = weaponItem.GetDamageType;
                hitSound   = weaponItem.HitSound;
            }

            //double hitNumber = GameEnvironment.Random.NextDouble();
            //if (hitNumber < HitChance())
            if (TryHit(target))
            {
                double attackValue = AttackValue();
                NonAnimationSoundEvent hitSoundEvent = new NonAnimationSoundEvent(hitSound);
                //no annimation for attacks (hit or miss) yet. when inplementing that, include sound effect there and remove this.
                LocalServer.SendToClients(hitSoundEvent);
                damageDealt = target.TakeDamage(attackValue, damageType);
            }
            else
            {
                //TODO: Display attack missed (visual feedback on fail)

                NonAnimationSoundEvent missSoundEvent = new NonAnimationSoundEvent("Sounds/Dodge");
                //no annimation for attacks (hit or miss) yet. when inplementing that, include sound effect there and remove this.
                LocalServer.SendToClients(missSoundEvent);
            }

            if (damageDealt > 0)
            {
                ProcessReflection(damageDealt, target);
            }
        }