iT邦幫忙

2024 iThome 鐵人賽

DAY 22
0
生成式 AI

生成式AI輔助電子遊戲製作系列 第 22

Day22 /技能資料實作

  • 分享至 

  • xImage
  •  

今天的文章要來把之前的寫好得技能實做到Button的物件讓他可以在遊戲裡實際被使用。

新增技能按鈕

我們先新增一個Button在之前做好的下面,我比較喜歡用舊的按鈕,不然也可以用上面的Button-TextMeshPro
https://ithelp.ithome.com.tw/upload/images/20241006/20169512c1CQYOlPkM.png

再把Button下面的Text刪掉,我們之後是要用圖片就先不用文字了。這裡可以看到滑鼠移到做好的Button上會有反饋了。
https://ithelp.ithome.com.tw/upload/images/20241006/20169512rAep0sWn1s.png

技能Code實作

把之前設計的技能讓ChatGPT實做出來。

參考先前想法的四個範例寫出code

1. 火焰衝擊(Flame Impact)

public class FlameImpact : ISkill
{
    public string SkillName => "Flame Impact";
    public int ManaCost => 12;
    public int Cooldown => 3;
    public int CurrentCooldown { get; set; } = 0;

    public void UseSkill(Character target)
    {
        if (CurrentCooldown == 0)
        {
            int damage = 20;
            target.TakeDamage(damage);
            target.UseMana(ManaCost);
            CurrentCooldown = Cooldown;
            Debug.Log($"{SkillName} hits {target.Name} for {damage} fire damage.");
        }
        else
        {
            Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
        }
    }

    public bool CanUseSkill(int currentMana)
    {
        return currentMana >= ManaCost && CurrentCooldown == 0;
    }
}

2. 治癒之光(Healing Light)

public class FlameImpact : ISkill
{
    public string SkillName => "Flame Impact";
    public int ManaCost => 12;
    public int Cooldown => 3;
    public int CurrentCooldown { get; set; } = 0;

    public void UseSkill(Character target)
    {
        if (CurrentCooldown == 0)
        {
            int damage = 20;
            target.TakeDamage(damage);
            target.UseMana(ManaCost);
            CurrentCooldown = Cooldown;
            Debug.Log($"{SkillName} hits {target.Name} for {damage} fire damage.");
        }
        else
        {
            Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
        }
    }

    public bool CanUseSkill(int currentMana)
    {
        return currentMana >= ManaCost && CurrentCooldown == 0;
    }
}

3. 雷霆連鎖(Thunder Chain)

public class ThunderChain : ISkill
{
    public string SkillName => "Thunder Chain";
    public int ManaCost => 18;
    public int Cooldown => 5;
    public int CurrentCooldown { get; set; } = 0;

    public void UseSkill(Character target)
    {
        if (CurrentCooldown == 0)
        {
            int primaryDamage = 15;
            int secondaryDamage = 10;
            target.TakeDamage(primaryDamage);
            // 假設有其他敵人可以被擊中
            // Implement secondary targets for the chain effect

            target.UseMana(ManaCost);
            CurrentCooldown = Cooldown;
            Debug.Log($"{SkillName} strikes {target.Name} for {primaryDamage} lightning damage, and chains to others.");
        }
        else
        {
            Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
        }
    }

    public bool CanUseSkill(int currentMana)
    {
        return currentMana >= ManaCost && CurrentCooldown == 0;
    }
}

4. 暗影詛咒(Shadow Curse)

public class ShadowCurse : ISkill
{
    public string SkillName => "Shadow Curse";
    public int ManaCost => 14;
    public int Cooldown => 3;
    public int CurrentCooldown { get; set; } = 0;

    public void UseSkill(Character target)
    {
        if (CurrentCooldown == 0)
        {
            int damage = 15;
            target.TakeDamage(damage);
            target.UseMana(ManaCost);
            CurrentCooldown = Cooldown;
            Debug.Log($"{SkillName} curses {target.Name}, dealing {damage} shadow damage and reducing their attack.");
        }
        else
        {
            Debug.Log($"{SkillName} is on cooldown for {CurrentCooldown} more turns.");
        }
    }

    public bool CanUseSkill(int currentMana)
    {
        return currentMana >= ManaCost && CurrentCooldown == 0;
    }
}


上一篇
D21/ 遊戲介面icon
下一篇
D23 /技能資料實作2
系列文
生成式AI輔助電子遊戲製作30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言