Skip to content

Commit

Permalink
Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli2 committed Jun 13, 2014
1 parent 77ac3ca commit 899ab46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/game/Spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ SpellBase * SpellManager::getSpellOnTarget(EntityHandle target, SpellType type)
return NULL;
}

void SpellManager::replaceCaster(EntityHandle oldCaster, EntityHandle newCaster) {
for(size_t i = 0; i < MAX_SPELLS; i++) {
SpellBase * spell = spells[SpellHandle(i)];

if(spell->m_exist && spell->m_caster == oldCaster) {
spell->m_caster = newCaster;
}
}
}


bool GetSpellPosition(Vec3f * pos, SpellBase * spell)
{
Expand Down
3 changes: 2 additions & 1 deletion src/game/Spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class SpellManager {
bool ExistAnyInstanceForThisCaster(SpellType typ, EntityHandle caster);

SpellBase * getSpellOnTarget(EntityHandle target, SpellType type);


void replaceCaster(EntityHandle oldCaster, EntityHandle newCaster);
private:
SpellBase m_spells[MAX_SPELLS];
};
Expand Down
9 changes: 1 addition & 8 deletions src/script/ScriptedIOControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,7 @@ class ReplaceMeCommand : public Command {
CheckForInventoryReplaceMe(ioo, io);
}
} else {

for(size_t i = 0; i < MAX_SPELLS; i++) {
SpellBase * spell = spells[SpellHandle(i)];

if(spell->m_exist && spell->m_caster == oldd) {
spell->m_caster = neww;
}
}
spells.replaceCaster(oldd, neww);

InventoryPos oldPos = removeFromInventories(io);

Expand Down

0 comments on commit 899ab46

Please sign in to comment.