【发布时间】:2014-01-05 22:32:08
【问题描述】:
我一直在为 FFXIV 开发一个模拟器;
我一直非常接近完成,然后我陷入了一个对象访问问题,我无法访问主要玩家的统计数据。我的项目可以在:https://github.com/eein/chocobro
我知道,我可以优化很多东西。 :P
基本上,我是一种蛮力操纵它以使对象能够访问他们需要的对象,但我正在寻找正确的做事方式。
我将开始重写它,所以不要太拘泥于示例代码,但它在那里可以看到我遇到的问题。 :(
理想情况下,在下一次尝试中,这是我想做的: 从一个包含有关播放器对象的所有信息的播放器类开始(将来,我想为全组模拟创建多个)。
类似:
int main(){
Player p = new Player();
public void setJob()
{
if (job == "bard"){ Player p = new Bard(); }
if (job == "warrior"){ Player p = new Warrior(); }
}
public class Player
{
private string name {get;set;}
private string job {get;set;}
private string STR;
private string DEX;
private string VIT;
//etc..
public virtual void rotation()
{
}
}
//I want to make the program a bit modular for jobs (roles/classes)
//So..
public class Bard : Player
{
public override void rotation()
{
heavyshot.execute();
//etc.
}
Ability heavyshot = new Heavyshot();
public class Heavyshot : Ability
{
public Heavyshot()
{
name = "Heavy Shot";
potency = 150;
dotPotency = 0;
recastTime = 2.5;
TPcost = 60;
animationDelay = 0.8;
abilityType = "Weaponskill";
castTime = 0.0;
duration = 0.0;
}
public override void impact()
{
//add heavier shot buff activation here
base.impact();
}
}
}
public class Ability{
public int cooldown;
public int cost;
public virtual void impact()
{
public virtual void impact()
{
//Deal some damage.
// !! - the key problem is here, i want to initiate a roll to compare to the players CRIT rating versus the roll to determine the bonus damage. But I can't access the initiated players crit from here. The rating may change depending on abilities used so I can't create a new object. I know i need an object reference but I can't figure it out...
log(time.ToString("F2") + " - " + name +
" Deals " + potency +
" Potency Damage. Next ability at: " + nextability);
}
}
我可能不太清楚,但基本上我希望能够从技能中获取玩家的暴击,并且我假设技能不能以这种方式设置以使其发挥作用。有谁知道我应该使用什么样的设计模式,以便能力中的虚函数可以访问父类球员的统计数据?
理想情况下,我希望吟游诗人类包含与吟游诗人职业相关的所有能力和统计更新,一旦吟游诗人继承了玩家并且对象被更改为引用吟游诗人对象,我如何使它成为由能力类在访问该函数时不需要在创建时对父级的对象引用。
我自己很困惑,但非常感谢理解我的胡言乱语并且可以提供帮助的人!
【问题讨论】: