예제 #1
0
        public static AdvancedMeleeWeapon GetAdvancedWeapon(MeleeWeapon weapon, Farmer user)
        {
            AdvancedMeleeWeapon advancedMeleeWeapon = null;

            if (advancedMeleeWeapons.ContainsKey(weapon.InitialParentTileIndex))
            {
                int skillLevel = -1;
                foreach (AdvancedMeleeWeapon amw in advancedMeleeWeapons[weapon.initialParentTileIndex])
                {
                    if (user == null || (amw.skillLevel <= user.getEffectiveSkillLevel(4) && amw.skillLevel > skillLevel))
                    {
                        skillLevel          = amw.skillLevel;
                        advancedMeleeWeapon = amw;
                    }
                }
            }
            if (advancedMeleeWeapon == null && advancedMeleeWeaponsByType.ContainsKey(weapon.type) && user != null)
            {
                int skillLevel = -1;
                foreach (AdvancedMeleeWeapon amw in advancedMeleeWeaponsByType[weapon.type])
                {
                    if (amw.skillLevel <= user.getEffectiveSkillLevel(4) && amw.skillLevel > skillLevel)
                    {
                        skillLevel          = amw.skillLevel;
                        advancedMeleeWeapon = amw;
                    }
                }
            }

            return(advancedMeleeWeapon);
        }
예제 #2
0
        public static void AddEnchantments(MeleeWeapon weapon)
        {
            AdvancedMeleeWeapon amw = GetAdvancedWeapon(weapon, null);

            if (amw != null && amw.enchantments.Any())
            {
                weapon.enchantments.Clear();
                foreach (AdvancedEnchantmentData aed in amw.enchantments)
                {
                    BaseWeaponEnchantment bwe = null;
                    switch (aed.type)
                    {
                    case "vampiric":
                        bwe = new VampiricEnchantment();
                        break;

                    case "jade":
                        bwe = new JadeEnchantment();
                        break;

                    case "aquamarine":
                        bwe = new AquamarineEnchantment();
                        break;

                    case "topaz":
                        bwe = new TopazEnchantment();
                        break;

                    case "amethyst":
                        bwe = new AmethystEnchantment();
                        break;

                    case "ruby":
                        bwe = new RubyEnchantment();
                        break;

                    case "emerald":
                        bwe = new EmeraldEnchantment();
                        break;

                    case "haymaker":
                        bwe = new HaymakerEnchantment();
                        break;

                    case "bugkiller":
                        bwe = new BugKillerEnchantment();
                        break;

                    case "crusader":
                        bwe = new CrusaderEnchantment();
                        break;

                    case "magic":
                        bwe = new MagicEnchantment();
                        break;

                    default:
                        bwe = new BaseWeaponEnchantment();
                        string key = aed.name;
                        context.Helper.Reflection.GetField <string>(bwe, "_displayName").SetValue(key);
                        break;
                    }
                    if (bwe != null)
                    {
                        weapon.enchantments.Add(bwe);
                        //context.Monitor.Log($"added enchantment {aed.type} to {weapon.Name} {weapon.enchantments.Count}");
                    }
                }
            }
        }
예제 #3
0
        public void GameLoop_UpdateTicking(object sender, StardewModdingAPI.Events.UpdateTickingEventArgs e)
        {
            //Monitor.Log($"player sprite frame {Game1.player.Sprite.currentFrame}");
            if (weaponAnimationFrame > -1 && advancedWeaponAnimating != null)
            {
                MeleeActionFrame frame = advancedWeaponAnimating.frames[weaponAnimationFrame];
                Farmer           user  = weaponAnimating.getLastFarmerToUse();

                if (weaponAnimationFrame == 0 && weaponAnimationTicks == 0)
                {
                    weaponStartFacingDirection = user.facingDirection.Value;
                    //Monitor.Log($"Starting animation, facing {weaponStartFacingDirection}");
                }

                if (user.CurrentTool != weaponAnimating)
                {
                    //Monitor.Log($"Switched tools to {Game1.player.CurrentTool?.DisplayName}");
                    weaponAnimating         = null;
                    weaponAnimationFrame    = -1;
                    weaponAnimationTicks    = 0;
                    advancedWeaponAnimating = null;
                    return;
                }
                if (frame.invincible != null)
                {
                    //Monitor.Log($"Setting invincible as {frame.invincible}");
                    user.temporarilyInvincible = (bool)frame.invincible;
                }

                if (weaponAnimationTicks == 0)
                {
                    //Monitor.Log($"Starting frame {weaponAnimationFrame}");

                    user.faceDirection((weaponStartFacingDirection + frame.relativeFacingDirection) % 4);
                    //Monitor.Log($"facing {user.getFacingDirection()}, relative {frame.relativeFacingDirection}");

                    if (frame.special != null)
                    {
                        try
                        {
                            switch (frame.special.name)
                            {
                            case "lightning":
                                LightningStrike(user, weaponAnimating, frame.special.parameters);
                                break;

                            case "explosion":
                                Explosion(user, weaponAnimating, frame.special.parameters);
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Monitor.Log($"Exception thrown on special effect:\n{ex}", LogLevel.Error);
                        }
                    }

                    if (frame.action == WeaponAction.NORMAL)
                    {
                        //Monitor.Log($"Starting normal attack");
                        user.completelyStopAnimatingOrDoingAction();
                        user.CanMove        = false;
                        user.UsingTool      = true;
                        user.canReleaseTool = true;
                        weaponAnimating.setFarmerAnimating(user);
                    }
                    else if (frame.action == WeaponAction.SPECIAL)
                    {
                        //Monitor.Log($"Starting special attack");
                        weaponAnimating.animateSpecialMove(user);
                    }

                    if (frame.trajectoryX != 0 || frame.trajectoryY != 0)
                    {
                        float   trajectoryX   = frame.trajectoryX;
                        float   trajectoryY   = frame.trajectoryY;
                        Vector2 rawTrajectory = TranslateVector(new Vector2(trajectoryX, trajectoryY), user.FacingDirection);
                        user.setTrajectory(new Vector2(rawTrajectory.X, -rawTrajectory.Y)); // game trajectory y is backwards idek
                        //Monitor.Log($"player trajectory {user.xVelocity},{user.yVelocity}");
                    }

                    if (frame.sound != null)
                    {
                        //Monitor.Log($"Playing sound {frame.sound}");
                        user.currentLocation.playSound(frame.sound, NetAudio.SoundContext.Default);
                    }
                    foreach (AdvancedWeaponProjectile p in frame.projectiles)
                    {
                        Vector2 velocity = TranslateVector(new Vector2(p.xVelocity, p.yVelocity), user.FacingDirection);
                        Vector2 startPos = TranslateVector(new Vector2(p.startingPositionX, p.startingPositionY), user.FacingDirection);

                        int damage = advancedWeaponAnimating.type > 0 ? p.damage * myRand.Next(weaponAnimating.minDamage, weaponAnimating.maxDamage) : p.damage;

                        //Monitor.Log($"player position: {user.Position}, start position: { new Vector2(startingPositionX, startingPositionY) }");

                        user.currentLocation.projectiles.Add(new BasicProjectile(damage, p.parentSheetIndex, p.bouncesTillDestruct, p.tailLength, p.rotationVelocity, velocity.X, velocity.Y, user.Position + new Vector2(0, -64) + startPos, p.collisionSound, p.firingSound, p.explode, p.damagesMonsters, user.currentLocation, user, p.spriteFromObjectSheet));
                    }
                }
                if (++weaponAnimationTicks >= frame.frameTicks)
                {
                    weaponAnimationFrame++;
                    weaponAnimationTicks = 0;
                    //Monitor.Log($"Advancing to frame {weaponAnimationFrame}");
                }
                if (weaponAnimationFrame >= advancedWeaponAnimating.frames.Count)
                {
                    //Monitor.Log($"Ending weapon animation");
                    user.completelyStopAnimatingOrDoingAction();
                    user.CanMove   = true;
                    user.UsingTool = false;
                    user.setTrajectory(Vector2.Zero);

                    if (user.IsLocalPlayer)
                    {
                        int cd = advancedWeaponAnimating.cooldown;
                        if (user.professions.Contains(28))
                        {
                            cd /= 2;
                        }
                        if (weaponAnimating.hasEnchantmentOfType <ArtfulEnchantment>())
                        {
                            cd /= 2;
                        }

                        switch (weaponAnimating.type.Value)
                        {
                        case 1:
                            MeleeWeapon.daggerCooldown = cd;
                            break;

                        case 2:
                            MeleeWeapon.clubCooldown = cd;
                            break;

                        case 3:
                            MeleeWeapon.defenseCooldown = cd;
                            break;
                        }
                    }
                    weaponAnimationFrame    = -1;
                    weaponAnimating         = null;
                    advancedWeaponAnimating = null;
                    weaponAnimationTicks    = 0;
                }

                return;
            }
        }
 public AdvancedEnchantment(MeleeWeapon w, AdvancedMeleeWeapon amw, AdvancedEnchantmentData aed)
 {
     weapon         = w;
     advancedWeapon = amw;
     enchantment    = aed;
 }