Skip to content

Commit

Permalink
feat: update skillId map
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivomo committed Jan 4, 2024
1 parent 250f80b commit 8d97756
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
3 changes: 3 additions & 0 deletions client/src/config/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,16 @@ export const Skills = [
{
type: 'hp',
name: 'HP Boost',
skillId: 1
},
{
type: 'spd',
name: 'SPD Surge',
skillId: 2
},
{
type: 'atk',
name: 'Chain ATK',
skillId: 0
},
]
44 changes: 17 additions & 27 deletions client/src/pages/ffa/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ const FFA = () => {
// console.log(GlobalData, 'GlobalData')

const curPlayer = PlayerData.find((player: any) => player.addr.toLocaleLowerCase() == account.address.toLocaleLowerCase()) || {};
console.log(PlayerData)

const [tab, setTab] = useState('home');
const [dialogVisible, setDialogVisible] = useState(false);
const [nameDialogVisible, setNameDialogVisible] = useState(false);
const [skillDialogVisible, setSkillDialogVisible] = useState(false);
const [battleResultDialogVisible, setBattleResultDialogVisible] = useState(false);
const [battleResult, setBattleResult] = useState('');
const [skillName, setSkillName] = useState('');
const [battleVisible, setBattleVisible] = useState(false);
const [mintState, setMintState] = useState('init');
const [fighting, setFighting] = useState(false);
Expand Down Expand Up @@ -221,9 +221,6 @@ const FFA = () => {
console.log(BattleResultData, 'BattleResultData')
}, [BattleResultData.length])

useEffect(() => {
setSkillId(curPlayer?.skillId)
}, [curPlayer?.skillId])

useEffect(() => {
const init = async () => {
Expand Down Expand Up @@ -255,7 +252,7 @@ const FFA = () => {
} else {
setTimeout(() => {

if (prevBattleIsWin && attacker.skillId === 2 && round % 1 === 0 && round <= 15) {
if (prevBattleIsWin && attacker.skillId === 0 && round % 1 === 0 && round <= 15) {
console.log('atk again');
setRound((prevState => prevState + 0.5));
} else {
Expand All @@ -275,7 +272,7 @@ const FFA = () => {
setLogs([...logs, {addr: defer.addr, win: false}]);
} else {
setTimeout(() => {
if (!prevBattleIsWin && defer.skillId === 2 && round % 1 === 0 && round <= 15) {
if (!prevBattleIsWin && defer.skillId === 0 && round % 1 === 0 && round <= 15) {
console.log('atk again');
setRound((prevState => prevState + 0.5));
} else {
Expand Down Expand Up @@ -307,34 +304,27 @@ const FFA = () => {

}

const selectSkill = (name) => {
const selectSkill = (id) => {
setSkillDialogVisible(true);
setSkillName(name);
setSkillId(id);
}

const startBattle = async () => {
const skillIndex = Skills.findIndex(item => item.name === skillName);
const skillType = Skills[skillIndex].type;
const _attacker = {...curPlayer};
const _defer = {...targetData.current};

if (_defer.skillId === 0) {
if (_defer.skillId === 1) {
_defer.hp += 100;
} else if (_defer.skillId === 1) {
} else if (_defer.skillId === 2) {
_defer.speed += 15;
}

switch (skillType) {
case 'spd':
_attacker.speed += 15;
_attacker.skillId = 1;
break;
case 'hp':
_attacker.hp += 100;
_attacker.skillId = 0;
break;
default:
_attacker.skillId = 2;
_attacker.skillId = skillId;

if (_attacker.skillId === 1) {
_attacker.hp += 100;
} else if (_attacker.skillId === 2) {
_attacker.speed += 15;
}

await chooseSkill(account, skillId);
Expand Down Expand Up @@ -505,7 +495,7 @@ const FFA = () => {
<Dialog visible={skillDialogVisible}>
<div className="skill-dialog-content">
<h3>Skill</h3>
<p>Select {skillName} as your skill</p>
<p>Select {Skills.find(item => item.skillId === skillId)?.name} as your skill</p>
<div className="opt-wrapper">
<button className="mi-btn" onClick={startBattle}>CONFIRM</button>
<button className="mi-btn" onClick={() => setSkillDialogVisible(false)}>Back</button>
Expand Down Expand Up @@ -545,7 +535,7 @@ const FFA = () => {
<ul className="skill-list">
{
Skills.map((item) => (
<li className={`skill-item skill-${item.type}`} key={item.name} onClick={() => selectSkill(item.name)}>
<li className={`skill-item skill-${item.type}`} key={item.name} onClick={() => selectSkill(item.skillId)}>
<div className="txt" >{item.name}</div>
</li>
))
Expand Down Expand Up @@ -594,12 +584,12 @@ const FFA = () => {
</div>

<ul className="skill-list attacker-skill">
<li className={`skill-item skill-${Skills.find(item => item.name === skillName)?.type}`}>
<li className={`skill-item skill-${Skills.find(item => item.skillId === skillId)?.type}`}>
</li>
</ul>

<ul className="skill-list defer-skill">
<li className={`skill-item skill-${Skills[targetData?.current?.skillId]?.type}`}>
<li className={`skill-item skill-${Skills.find(item => item.skillId === targetData?.current?.skillId)?.type}`}>
</li>
</ul>

Expand Down

0 comments on commit 8d97756

Please sign in to comment.