void Unit::setUnitType(UNIT_TYPE type) { m_unitType = type; switch (type) { case UNIT_TYPE::ASSAULT: setWeapon(WeaponFactory::getInstance()->getNewWeapon(WeaponType::AK1)); m_light->setColor(sf::Color::Yellow); break; case UNIT_TYPE::CQB: setWeapon(WeaponFactory::getInstance()->getNewWeapon(WeaponType::PLASMA1)); m_light->setColor(sf::Color::Magenta); break; case UNIT_TYPE::SNIPER: setWeapon(WeaponFactory::getInstance()->getNewWeapon(WeaponType::SNIPER1)); m_light->setColor(sf::Color::Red); break; case UNIT_TYPE::PLAYER: setWeapon(WeaponFactory::getInstance()->getNewWeapon(WeaponType::PISTOL)); m_light->setColor(sf::Color::White); break; } }
/*********************************************************************** * Character * swapWeapons ***********************************************************************/ void fired::Character::swapWeapons() { if (weaponCooldown.isActive()) return; swapItems(&inventory->primaryWeapon, &inventory->secondaryWeapon); swapItems(&inventory->primaryAmmo , &inventory->secondaryAmmo); if (inventory->primaryWeapon.base) setWeapon(container->weapons[inventory->primaryWeapon.base->UID]); else setWeapon(base->weapon); if (inventory->primaryAmmo.base) ammo = container->ammos[inventory->primaryAmmo.base->UID]; else ammo = base->ammo; weaponCooldown.setTimer(WEAPON_SWITCH_COOLDOWN); }
/*********************************************************************** * Character * updateEquip ***********************************************************************/ void fired::Character::updateEquip() { emptyStats(&equipStats); if (helm) helm = NULL; if (arms) arms = NULL; if (legs) legs = NULL; if (body) body = NULL; if (shoe) shoe = NULL; if (fist) fist = NULL; if (inventory->helm.base) { helm = container->armors[inventory->helm.base->UID]; equipStats.armor += helm->armor; } if (inventory->body.base) { body = container->armors[inventory->body.base->UID]; equipStats.armor += body->armor; } if (inventory->arms.base) { arms = container->armors[inventory->arms.base->UID]; equipStats.armor += arms->armor; } if (inventory->fist.base) { fist = container->armors[inventory->fist.base->UID]; equipStats.armor += fist->armor; } if (inventory->legs.base) { legs = container->armors[inventory->legs.base->UID]; equipStats.armor += legs->armor; } if (inventory->shoe.base) { shoe = container->armors[inventory->shoe.base->UID]; equipStats.armor += shoe->armor; } if (inventory->primaryWeapon.base) setWeapon(container->weapons[inventory->primaryWeapon.base->UID]); else setWeapon(base->weapon); if (inventory->primaryAmmo.base) ammo = container->ammos[inventory->primaryAmmo.base->UID]; else ammo = base->ammo; updateModel(); }
void player::use(int index){ //WEAPON,ARMOR,CONSUMABLE,ETC Item tmp = load::getItemData(getItemList()->at(index).getID()); if(tmp.getItemType() == "WEAPON"){ getStat()->addAll(0-getWeapon().getiAtk(),0-getWeapon().getiDef(),0-getWeapon().getiMaxHp()); getItemList()->at(index) = load::getItemData(getWeapon().getID()); if(getItemList()->at(index).getID() == 1)delItem(index); setWeapon(tmp.getID()); getStat()->addAll(tmp.getiAtk(),tmp.getiDef(),tmp.getiMaxHp()); cout << "\n\tEquipe "<<tmp.getName()<<endl; }else if(tmp.getItemType() == "ARMOR"){ getStat()->addAll(0-getArmor().getiAtk(),0-getArmor().getiDef(),0-getArmor().getiMaxHp()); getItemList()->at(index) = load::getItemData(getArmor().getID()); if(getItemList()->at(index).getID() == 2)delItem(index); setArmor(tmp.getID()); getStat()->addAll(tmp.getiAtk(),tmp.getiDef(),tmp.getiMaxHp()); cout << "\n\tEquipe "<<tmp.getName()<<endl; }else if(tmp.getItemType() == "CONSUMABLE"){ getStat()->addAll(tmp.getiAtk(),tmp.getiDef(),tmp.getiMaxHp()); getStat()->addHp(tmp.getiHp()); delItem(index); cout << "\tUse "<<tmp.getName()<<endl; }else{ cout << "\n\tCannot use "<<tmp.getName()<<endl; } getch(); }
//When an actor is loaded //handles building weapons and model and such void ActorPlayer::Load(Json::Value & parentValue, LoadData & loadData) { //Load this class' data PhysicsActor::Load(parentValue,loadData); //Setup the weapons VoxEngine::SynchronousTask.RequestTask([this]() { // Create the weapons only if none were loaded if (weapons.size() <= 0) { //Setup weapons weapons.push_back(Game()->Actors.BuildWeapon("playerlasercannon.json",this)); weapons.push_back(Game()->Actors.BuildWeapon("playerpulselaser.json",this)); //The pulse laser starts unpurchased weapons[1]->Modifiers.DamageFactor = 0.0f; } // Set initial weapon to pulse laser setWeapon(currentWeaponId); }); }
void TurretDataComponent::initializeTransientMembers() { ManagedReference<SceneObject*> turret = getParent(); if (turret == NULL) { return; } templateData = dynamic_cast<SharedInstallationObjectTemplate*>(turret->getObjectTemplate()); SceneObject* sceneObject = turret->getSlottedObject("hold_r"); if (sceneObject == NULL) { return; } WeaponObject* weapon = cast<WeaponObject*>(sceneObject); setWeapon(weapon); }
//Update the position based off the most recent movement and direction vectors bool ActorPlayer::Update() { // If the weapon is null, don't do shit if(currentWeapon == NULL) return PhysicsActor::Update(); // Get the movement vector from the first person controller vec2 moveVector = Game()->FirstPerson->GetMoveVector(); // Calculate the direction we are facing facingDirection = atan2(moveVector.y, moveVector.x); // Calculate the magnitude of the movement vector (are we sprinting) float magnitude = glm::length(moveVector); // Check if we should switch weapons if(Game()->FirstPerson->GetSwitchWeaponRequested()) { //switch weapons to the next weapon which has been purchased for (int i = (currentWeaponId+1) % weapons.size(); i != currentWeaponId; i = (i+1) % weapons.size()) { //A damage factor of <= 0 indicates the weapon is currently locked if (weapons[i]->Modifiers.DamageFactor > 0) { setWeapon(i); break; } } } // Update the weapon currentWeapon->Update(Game()->FirstPerson->GetLookVector(), weaponPos); // Forward whether or not we want to shoot to the player's weapon animation controller bool r = currentWeapon->HoldingTrigger(Game()->FirstPerson->GetTriggerPulled()); model->Controller()->SetBoolean("firing", r); // if we fired the weapon, update the state machine //but only if its not the pulseLaser, no idea why if(r && (currentWeaponId == 0)) model->Update(SIMULATION_DELTA, Game()->Now()); // Forward the weapon mode to the controller model->Controller()->SetBoolean("mode", (currentWeaponId == 0) ? true : false); // Forward the movement speed to the player's weapon animation controller model->Controller()->SetFloat("speed", OnGround() ? magnitude : 0.0f); // Use the movement vector to set the velocity of the player's physics object Velocity.x = moveVector.x * movementSpeed; Velocity.y = moveVector.y * movementSpeed; // Have we walked more than 200 units? if(deltaPosition > 200 && OnGround()) { // Fire the actor walked event Game()->Actors.ActorWalked.Fire([this](function<void(ActorPlayer*)> subscriber) { subscriber(this); }); //cout << "Player Position: " << Position.x << "," << Position.y << "," << Position.z << endl; deltaPosition -=200; } // If we haven't, check if we should add more distance to our odometer else { if(OnGround()) { deltaPosition+= sqrt(pow(Velocity.x,2)+pow(Velocity.y,2)); } } // Lets check if the controller wants us to jump if(Game()->FirstPerson->GetJumpRequested()) { // Check that the user is on the ground //and does not have any velocity upwards if (OnGround() && (Velocity.z < .025)) { // Apply upwards velocity Velocity.z += jumpVelocity; // First the event that we'e Game()->Actors.ActorJumped.Fire([this](function<void(ActorPlayer*)> subscriber) { subscriber(this); }); } } //Run autojump? if (VoxEngine::SavedDeviceData.GameOptions.Autojump > 0) { //Autojump if (glm::length(moveVector) > .15) { //Only jump if you're touching ground bool touchingGround = (OnGround() && Velocity.z < .2); //Check if you've got terrain (cliff/hill) directly in front of you //Check just a bit above your feet float feetHeight = Position.z-Size.z/2.0f; float checkHeight = feetHeight+.5f; float rayLength; vec3 surfaceNormal; vec3 traceDirection = vec3(moveVector,0); if (Game()->Voxels.RaytraceToTerrain(vec3(Position.x,Position.y,checkHeight),traceDirection,rayLength,surfaceNormal)) { if (rayLength < 1.5) { //Check the height of the given location //add .15 to go pas the surface and onto the voxel itself vec3 upcomingTerrain = vec3(Position.x,Position.y,checkHeight) + traceDirection*(rayLength+.15f); float upcomingHeight = Game()->Voxels.GetPositionHeight(vec2(upcomingTerrain)); //Now check if you're too low if (feetHeight+.15 < upcomingHeight) { if (touchingGround) { //Ok lets jump up //Playing some kind of jump animation would be A+ Velocity.z += min(15*(upcomingHeight-feetHeight),20.0f); //jump! } } } } } } // Return the result of the update of the super class return PhysicsActor::Update(); }
void Hero::useItem(Item* i) { if (i->getAttack() > 0) setWeapon(i); if (i->getDefense() > 0) setShield(i); if (health > 0) usePotion(i); }
Character::Character() : w_(nullptr) { // By default it gets a gun setWeapon(new Gun()); }