BOOL CCommandsDlg::OnInitDialog() { CDialog::OnInitDialog(); m_lstCommands.SetTabStops(96); int nCount = g_nCommandCount; CFile fileout; fileout.Open("c:/commandlist.txt", CFile::modeCreate | CFile::modeWrite); for (int n = 0; n < nCount; n++) { CString strLine; char c = g_Commands[n].m_nKey; CString strKeys = c; for (int k = 0; k < g_nKeyCount; k++) { if (g_Keys[k].m_nVKKey == g_Commands[n].m_nKey) { strKeys = g_Keys[k].m_strName; break; } } CString strMod(""); if (g_Commands[n].m_nModifiers & RAD_SHIFT) strMod = "Shift"; if (g_Commands[n].m_nModifiers & RAD_ALT) strMod += (strMod.GetLength() > 0) ? " + Alt" : "Alt"; if (g_Commands[n].m_nModifiers & RAD_CONTROL) strMod += (strMod.GetLength() > 0) ? " + Control" : "Control"; if (strMod.GetLength() > 0) { strMod += " + "; } strLine.Format("%s \t%s%s", g_Commands[n].m_strCommand, strMod, strKeys); m_lstCommands.AddString(strLine); strLine.Format("%s \t\t\t%s%s", g_Commands[n].m_strCommand, strMod, strKeys); fileout.Write(strLine, strLine.GetLength()); fileout.Write("\r\n", 2); } fileout.Close(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void Actor::attack(Actor * a) { Weapon * w = activeWeapon(); if (w!=NULL) { float distanceToTarget = ofVec2i(x, y).distance(ofVec2i(a->x, a->y)) * FEET_PER_TILE; // 5 feet per square int roll = d20(); bool hit = false; bool crit = false; ofPtr<CombatEvent> ce = ofPtr<CombatEvent>(new CombatEvent()); ce->a = this; ce->b = a; ce->type = CombatEvent::MISS_EVENT; ce->dmg = 0; int ac = a->ac(); int attackBonus = data.tohit + w->data.toHit; int damageBonus = data.damageBonus + w->data.damageBonus; if (type==Object::Player) { attackBonus = data.tohit + w->data.toHit; switch (w->data.weaponType) { case Weapon::LIGHT_WEAPON: case Weapon::REACH_WEAPON: case Weapon::DOUBLE_WEAPON: case Weapon::ONE_HANDED_WEAPON: case Weapon::TWO_HANDED_WEAPON: { attackBonus += strMod() ; break; } case Weapon::THROWN_WEAPON: case Weapon::PROJECTILE_WEAPON: case Weapon::AMMUNITION_WEAPON: { attackBonus += dexMod() ; } } attackBonus += level(); damageBonus = 1 + w->data.damageBonus; } switch (w->data.weaponType) { case Weapon::THROWN_WEAPON: case Weapon::PROJECTILE_WEAPON: case Weapon::AMMUNITION_WEAPON: { attackBonus -= MAX(0,distanceToTarget - w->data.range) / FEET_PER_TILE; } } //ofLog() << getName() << " > target ac: " << ac << " tohit: "<<attackBonus<<" damageBonus: "<<damageBonus; //ofLog() << "attack roll: " << roll << " +" << attackBonus << ", against ac: "<<ac; if (roll==1) { // whiff!! hit = false; } else if (roll>=w->data.criticalThreat) { //ofLog() << "Crit!"; // have critical threat, but roll again... roll = d20(); if (roll+attackBonus>=ac) { crit = true; ce->type = CombatEvent::CRIT_EVENT; } else { hit = true; ce->type = CombatEvent::HIT_EVENT; } } else if (roll+attackBonus>=ac) { hit = true; ce->type = CombatEvent::HIT_EVENT; } if (crit||hit) { ce->dmg = w->rollAttack() + damageBonus; if (crit) { for (int i=1; i<w->data.criticalMultiplier; i++) { ce->dmg += w->rollAttack() + damageBonus; } } } if (ce->dmg ==0) ce->type = CombatEvent::MISS_EVENT; if (w->data.weaponType == Weapon::PROJECTILE_WEAPON) { ofPtr<CombatEvent> ae = ofPtr<CombatEvent>(new CombatEvent()); ae->a = this; ae->b = a; ae->nextEvent = ce; ae->type = CombatEvent::ARROW_EVENT; ofNotifyEvent(CombatEvent::combatEvent, *ae); } else { ofNotifyEvent(CombatEvent::combatEvent, *ce); } //a->takeDamage(ce->dmg); // TODO: move this logic to a combat resolution class actionDebt += ((float)w->data.attackDebt) * ((float)data.attackSpeed / 100.0f); } else { ofLog() << getName() << " has no weapon in hand!"; } return 0; }