コード例 #1
0
    public void attack(EntityHP target)
    {
        //make a new attack instance as a child of the action group object
        Attack att = Instantiate(ObjectManager.getAction("Attack"), mActions.transform).GetComponent <Attack>();

        //set target
        att.setTarget(target);
        //add the action to the action group component
        mActions.clearAddAction(att);
    }
コード例 #2
0
    public override TaskStatus OnUpdate()
    {
        CanMoveToRandomPoint();

        if (!_pauseAttackToMove)
        {
            if (CanCatchUpWithPlayer() && !IsWithinRange())
            {
                SetDestination(Target());
                canAttack.Value = false;
            }
            else
            {
                Stop();
                canAttack.Value = true;
            }
        }
        else
        {
            MoveToRandomPoint();
            if (HasArrived())
            {
                _movingToRandomPoint = false;
                _pauseAttackToMove   = false;
                canAttack.Value      = true;
            }
        }

        if (target.Value)
        {
            EntityHP hp = target.Value.GetComponent <EntityHP>();
            if (hp)
            {
                if (hp.currentHP <= 0)
                {
                    return(TaskStatus.Success);
                }
                else
                {
                    return(TaskStatus.Running);
                }
            }
            else
            {
                return(TaskStatus.Running);
            }
        }
        else
        {
            return(TaskStatus.Failure);
        }
    }
コード例 #3
0
		public override string ToString() {
			return Frames.ToString().PadLeft(4, ' ') + (Jump ? ",Jump" : "") + (Save ? ",Save" : "") + (Fire ? ",Fire" : "") + (Bash ? ",Bash" : "") +
				(ChargeJump ? ",CJump" : "") + (Glide ? ",Glide" : "") + (Start ? ",Start" : "") + (Select ? ",Select" : "") + (UI ? ",UI" : "") +
				(Action ? ",Action" : "") + (Esc ? ",Esc" : "") + (Dash ? ",Dash" : "") + (Grenade ? ",Grenade" : "") +
				Axis() + (DLoad ? ",DLoad" : "") + (DSave ? ",DSave" : "") + (SaveSlot >= 0 ? ",Slot," + (SaveSlot + 1) : "") +
				(!Position ? "" : ",Pos," + PositionX.ToString("0.####") + "," + PositionY.ToString("0.####")) +
				(!Speed ? "" : ",Speed," + SpeedX.ToString("0.####") + "," + SpeedY.ToString("0.####")) +
				(XP >= 0 ? ",XP," + XP : "") + (Color ? ",Color" : "") + (Random >= 0 ? ",Random," + Random : "") +
				(!EntityPos ? "" : ",EntityPos," + EntityPosX.ToString("0.####") + "," + EntityPosY.ToString("0.####")) +
				(!BlockPos ? "" : ",BlockPos," + BlockPosX.ToString("0.####") + "," + BlockPosY.ToString("0.####")) +
				(EntityHP < 0 ? "" : ",EntityHP," + EntityHP.ToString("0.##")) + (HP >= 0 ? ",HP," + HP.ToString("0.#") : "") + (EN >= 0 ? ",EN," + EN.ToString("0.##") : "") +
				(Restore ? ",Restore" : "") + (Copy >= 0 ? ",Copy," + (Copy + 1) : "") + (SkillTree >= 0 ? ",SkillTree," + SkillTree : "") +
				(MouseX < 0 && MouseY < 0 ? "" : ",Mouse," + MouseX.ToString("0.####") + "," + MouseY.ToString("0.####"));
		}
コード例 #4
0
    void Update()
    {
        transform.position += transform.forward * Time.deltaTime * movementSpeed;

        RaycastHit hit;

        if (Physics.Raycast(transform.position + transform.forward, transform.forward, out hit, collisionDistance))
        {
            EntityHP hp = hit.transform.GetComponent <EntityHP>();
            if (hp)
            {
                hp.TakeDamage(damage);
            }
            if (impact)
            {
                GameObject p = Instantiate(impact, transform.position, Quaternion.identity) as GameObject;
                Destroy(p, 1f);
            }
            Destroy(gameObject);
        }
    }
コード例 #5
0
ファイル: InfoMenu.cs プロジェクト: kevinkraft/RTS_4
    //-------------------------------------------------------------------------------------------------
    // public methods
    //-------------------------------------------------------------------------------------------------
    public void populate(Entity ent)
    {
        //clear menu
        clear();
        //populate the info for the Entity
        string  text = string.Format("Name: {0}\n", ent.mName);
        Vector3 epos = ent.transform.position;

        text += string.Format("Pos: ({0:0},{1:0})\n", epos.x, epos.z);
        EntityHP ent_hp = ent as EntityHP;

        if (ent)
        {
            //TEMP, see if the entity is in the visible  list
            foreach (Entity e in ObjectManager.getVisibleEntities())
            {
                if (ent == e)
                {
                    text += string.Format("Is Visible: True\n");
                    break;
                }
            }
        }
        if (ent_hp)
        {
            text += string.Format("HP: {0:0} \n", ent_hp.mHP);
        }
        EntityAction ent_act = ent as EntityAction;
        Unit         unit    = ent as Unit;

        if (ent_act)
        {
            if (!unit)
            {
                text += string.Format("InvCap.: {0:0} \n", ent_act.getInventory().mCapacity);
            }
            if (ent_act.mTown)
            {
                text += string.Format("Town: {0}\n", ent_act.mTown.mName);
                //text += string.Format("StockPile: {0}\n", ent_act.mTown.mStockpile.mName);
            }
        }
        Resource res = ent as Resource;

        if (res)
        {
            text += string.Format("Amount: {0:0} \n", res.mAmount);
        }
        //unit
        if (unit)
        {
            //hunger
            text += string.Format("Hunger: {0:0}\n", unit.getHunger());
            //garrison status
            if (unit.isGarrisoned())
            {
                text += string.Format("Garrison: {0}\n", unit.getGarrison().mName);
                setupUnitUngarrisonButton(unit, mButton1);
            }
            //gender
            text += string.Format("Gender: {0}\n", unit.getGender().ToString());
            //pregnancy
            if (unit.getGender() == GameTypes.GenderType.Female)
            {
                text += string.Format("Pregnant: {0}\n", unit.isPregnant().ToString());
                if (unit.isPregnant())
                {
                    text += string.Format("Preg.Prog.: {0:0}\n", unit.getPregnancyProgress());
                }
            }
            text += unit.printStats();
        }
        Building build = ent as Building;

        if (build)
        {
            text += string.Format("GarrisonCap.: {0}\n", build.getUnitInventory().mCapacity);
            text += string.Format("Garrisoned: {0}\n", build.getUnitInventorySize());
            if (build.getUnitInventorySize() > 0)
            {
                //make the ungarrisonall button
                setupBuildingUngarrisonButton(build, mButton1);
            }
        }
        Construction constro = ent as Construction;

        if (constro)
        {
            text += constro.printMaterialsMap();
            text += string.Format("Progress: {0:0}", constro.getProgress());
        }
        WorkedBuilding wb = ent as WorkedBuilding;

        if (wb)
        {
            text += string.Format("Progress: {0:0}\n", wb.displayProgress());
            text += string.Format("NumWorkers: {0}/{1}\n", wb.getNWorkers(), wb.getMaxWorkers());
            WorkedProdBuilding wpb = wb as WorkedProdBuilding;
            if (wpb)
            {
                text += wpb.printNeededItems();
            }
        }
        mText.text = text;
    }
コード例 #6
0
 public void setTarget(EntityHP target)
 {
     mTarget = target;
 }
コード例 #7
0
    private List <string> getAvailableActionStrings()
    {
        //returns a list of strings which are the names of available actions
        List <string> titles = new List <string>();
        Entity        ent    = mHitObject as Entity;

        if (ent)
        {
            titles.Add("Move");
            titles.Add("Wait");
        }
        else if (mHitPoint != Globals.InvalidPosition)
        {
            titles.Add("Move");
            titles.Add("Wait");
            titles.Add("Construct");
        }
        else if (mHitPoint == Globals.InvalidPosition)
        {
            //Debug.Log("Adding explore to menu list");
            titles.Add("Explore");
        }
        EntityHP ent_hp = mHitObject as EntityHP;

        if (ent_hp)
        {
            titles.Add("Attack");
        }
        EntityAction ent_act = mHitObject as EntityAction;

        if (ent_act)
        {
            titles.Add("Exchange");
        }
        Building build = mHitObject as Building;

        if (build)
        {
            titles.Add("Garrison");
            titles.Add("Procreate");
            if (build.getType() == GameTypes.BuildingType.TownHall)
            {
                titles.Add("Travel");
            }
        }
        Resource res = mHitObject as Resource;

        if (res)
        {
            titles.Add("Collect");
        }
        WorkedBuilding wb = mHitObject as WorkedBuilding;

        if (wb)
        {
            titles.Add("Work");
        }
        Construction constr = mHitObject as Construction;

        if (constr)
        {
            titles.Add("Construct");
        }


        return(titles);
    }
コード例 #8
0
    public void setOutcome(string oname)
    {
        EntityHP       ent_hp  = mHitObject as EntityHP;
        EntityAction   ent_act = mHitObject as EntityAction;
        Entity         ent     = mHitObject as Entity;
        Resource       res     = mHitObject as Resource;
        Building       build   = mHitObject as Building;
        Construction   constro = mHitObject as Construction;
        WorkedBuilding wb      = mHitObject as WorkedBuilding;

        mOutcomeString = oname;
        switch (oname)
        {
        case "Move":
            //Debug.Log(string.Format("Action keyword Move chosen", oname));
            Movement move = ObjectManager.initMove(mSelection.transform);
            if (ent)
            {
                move.setDestination(ent);
            }
            else if (mHitPoint != Globals.InvalidPosition)
            {
                move.setDestination(mHitPoint);
            }
            mOutcomeAction = move;
            break;

        case "Wait":
            Wait wt = ObjectManager.initWait(mSelection.transform);
            if (ent)
            {
                wt.setDestination(ent);
            }
            else if (mHitPoint != Globals.InvalidPosition)
            {
                wt.setDestination(mHitPoint);
            }
            mOutcomeAction = wt;
            break;

        case "Attack":
            //Debug.Log(string.Format("Action keyword Attack chosen.", oname));
            Attack att = ObjectManager.initAttack(mSelection.transform);
            if (ent_hp)
            {
                att.setTarget(ent_hp);
                mOutcomeAction = att;
                break;
            }
            else
            {
                mOutcome = false;
            }
            setActive(false);
            return;

        case "Exchange":
            Exchange ex = ObjectManager.initExchange(mSelection.transform);
            if (ent_act)
            {
                ex.setTarget(ent_act);
                mOutcomeAction = ex;
                break;
            }
            else
            {
                mOutcome = false;
            }
            setActive(false);
            return;

        case "Garrison":
            Garrison gar = ObjectManager.initGarrison(mSelection.transform);
            if (build)
            {
                gar.setTarget(build);
                mOutcomeAction = gar;
                break;
            }
            else
            {
                mOutcome = false;
            }
            setActive(false);
            return;

        case "Procreate":
            Procreate proc = ObjectManager.initProcreate(mSelection.transform);
            if (build)
            {
                proc.setGarrisonBuilding(build);
                mOutcomeAction = proc;
                break;
            }
            else
            {
                mOutcome = false;
            }
            setActive(false);
            return;

        case "Collect":
            Collect coll = ObjectManager.initCollect(mSelection.transform);
            if (res)
            {
                coll.setTarget(res);
                mOutcomeAction = coll;
                break;
            }
            else
            {
                mOutcome = false;
            }
            setActive(false);
            return;

        case "Work":
            Work wr = ObjectManager.initWork(mSelection.transform);
            if (wr)
            {
                wr.setTarget(wb);
                mOutcomeAction = wr;
                break;
            }
            else
            {
                mOutcome = false;
            }
            setActive(false);
            return;

        case "Construct":
            if (constro)
            {
                Construct constr = ObjectManager.initConstruct(mSelection.transform);
                constr.setTarget(constro);
                mOutcomeAction = constr;
            }
            else if (mHitPoint != Globals.InvalidPosition)
            {
                populateListMenu();
                //constr.setTarget(mHitPoint);
            }
            else
            {
                mOutcome = false;
                setActive(false);
                return;
            }
            break;

        case "Explore":
            //Debug.Log("Explore action set as outcome");
            Explore exp = ObjectManager.initExplore(mSelection.transform);
            mOutcomeAction = exp;
            break;

        case "Travel":
            //Debug.Log("travel selected");
            Travel trav = ObjectManager.initTravel(mSelection.transform);
            if (build)
            {
                //Debug.Log("building is not null");
                trav.setDestination(build);
                mOutcomeAction = trav;
                break;
            }
            else
            {
                mOutcome = false;
                //Debug.Log("building is null");
            }
            setActive(false);
            break;

        default:
            Debug.LogError(string.Format("Action keyword {0} not recoginised.", oname));
            break;
        }
        if (!mListActive)
        {
            mOutcome = true;
        }
    }