- Home /
Best Way To Handle Multiple Moves (Like Pokemon)?
Hi all, need a bit of help with this. I want to basally have monsters that can pull from a giant list of all available moves to put in their available moves list, which then i can refer to when I need to use the attack for it's info. I'm having a problem with seeing how I could do this, and the solution I'm working with right now is limited (such as I can refer forward but not back, meaning I can't have cooldown on moves). What's the best way to approach this?
Current Setup:
Class used when using a move:
using UnityEngine;
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
public class MonsterMoves : MonoBehaviour, IAbility{
public List<MoveInfo> Moves = new List<MoveInfo>();
public void Use(string MoveName, Vector3 Pos, Quaternion Rot){
Debug.Log ("Used " + MoveName + "!");
MethodInfo mi = this.GetType().GetMethod("Use" + MoveName);
mi.Invoke (this, new object[] {"Ember", Pos, Rot});
}
public void UseEmber(string MoveName, Vector3 PosToStart, Quaternion Rot){
ProjectileAttk (MoveName, PosToStart, Rot);
}
//Attk Types
public void ProjectileAttk(string MoveName, Vector3 PosToStart, Quaternion Rot){
GameObject temp = (GameObject) Instantiate (Moves[0].ParticleEffect, PosToStart, Rot);
temp.audio.clip = Moves[0].SoundEffect;
temp.audio.Play ();
}
}
public interface IAbility {
//Fill this with all the move types (projectile, transformation, etc)
void Use(string MoveName, Vector3 Pos, Quaternion Rot);
void ProjectileAttk (string MoveName, Vector3 Pos, Quaternion Rot);
}
[System.Serializable]
public class MoveInfo{
public string Name;
public float CooldownTime;
public GameObject ParticleEffect;
public AudioClip SoundEffect
}
How I refer to use a move currently (In the monster class):
GameObject.FindGameObjectWithTag("MainStuff").GetComponent<MonsterMoves>().Use (KnownMoves[AttkNum], transform.position, transform.rotation);
Answer by Stardog · Jan 10, 2015 at 09:58 AM
To make a massive list of every ability, you could make a static Dictionary
, and use the unique string to get the info about that ability. That will only work if Pokemon are using the exact moves from this dictionary. If you have instantiated/copied the moves they will be different, but if the Pokemon are referencing the moves from the Dictionary, they will be the same.
I would have an Abilities component on every Pokemon, which holds a list of 4 moves/abilities (List abilities).
public class Abilities : Monobehaviour {
public List<Ability> abilities;
public void AddMove(string dictionaryKeyID)
{
// Code that checks you don't already have 4 moves, etc, etc
// Add move - using its unique string in the dictionary.
abilities.Add(AbilityDatabaseScript.abilityDictionary[dictionaryKeyID]);
}
}
Now you can add moves like Addmove("tackle")
;
Each ability would have its own abstract base script:
public abstract class Ability : Monobehaviour {
public string _name;
public string _description;
public int _baseDamageAmount;
public AudioClip _soundEffect;
// Other vars that EVERY ability will have
public abstract IEnumerator DoAbility(Pokemon target);
}
Then the ability itself with unique DoAbility code.
public class Tackle : Ability {
public override IEnumerator DoAbility(Pokemon target)
{
// Your battle system will have to run this function, without even knowing what the move is. The battle system will also play the audio, animations, etc.
}
}
This is a nice solution, thanks for the help. Want to make sure though, so each move I add to the game I just create a new class for it in the same script that I created the Tackle, right?
A look at my code now :
http://hastebin.com/uvacebuvum.vala
http://hastebin.com/cubediquwi.vala
http://hastebin.com/ihazagebet.vala
Could you tell me how you'd put the skills in the dictionary? Say your Tackle ability for example.
Answer by AwesumeOne · Jan 10, 2015 at 08:57 AM
You could try to Enum the moves? Each move have a few values set to them, such as attack power, defense power. The cooldown could be set to each move as well, just ones that don't need it have it set to zero.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180035im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Add force on the ball based in Mouse Drag 0 Answers
How to build a road? 1 Answer
Having trouble with grid movement 1 Answer