Пример #1
0
        public virtual VBItem DropItem(InventoryObjectItem i)
        {
            Inventory.Remove(i);

            if (i.Juice == 0)
            {
                return(null);
            }

            VBItem tmp = Entities.Instance.Create(i.ItemType, Map.Instance) as VBItem;

            tmp.Position = Position;

            MultipleActionItem matmp = tmp as MultipleActionItem;

            if (matmp != null)
            {
                matmp.ActionMode = i.ActionMode;

                ConsumableItem ctmp = tmp as ConsumableItem;
                if (ctmp != null)
                {
                    ctmp.Juice = i.Juice;
                }
            }

            tmp.PostCreate();
            tmp.PhysicsModel.Bodies[0].ClearForces();

            return(tmp);
        }
Пример #2
0
        //VB
        protected virtual bool InTaskRange(float needDistance = 3.5f)
        {
            Vec3 targetPos;

            if (currentTask.Entity != null)
            {
                targetPos = currentTask.Entity.Position;
            }
            else
            {
                targetPos = currentTask.Position;
            }

            float distance = (ControlledObject.Position - targetPos).Length();

            if (distance != 0)
            {
                Range range = new Range(0, needDistance);

                if (currentTask.Type == Task.Types.Attack)
                {
                    MultipleActionItem itm = (ControlledObject as VBCharacter).ActiveHeldItem as MultipleActionItem;

                    if (itm != null)
                    {
                        range = itm.GetCurActionMode().UseDistanceRange;
                    }
                }

                if (distance >= range.Minimum && distance <= range.Maximum)
                {
                    //stop
                    ControlledObject.Stop();
                    RTSCharacter character = ControlledObject as RTSCharacter;
                    if (character != null)
                    {
                        character.SetLookDirection(targetPos);
                    }
                    return(true);
                }
                else
                {
                    //move to target
                    ControlledObject.Move(targetPos);
                    return(false);
                }
            }

            return(true);
        }
Пример #3
0
        public void BaseAttack(Dynamic ent, string skill)
        {
            foreach (MapObject m in ObjectsInPath(this, ent))
            {
                Log.Info("Objects in path {0}", m.Name);
            }

            MultipleActionItem mTmp = activeHeldItem as MultipleActionItem;

            if (mTmp != null && mTmp.Use(ent))
            {
                //remove action points, play sound, apply damage
                Intellect.IncActionPts(-mTmp.GetCurActionMode().ActionPoints);
                ent.DoDamage(this, Position, null, GetNetDamage(ent), false);
                SoundPlay3D(mTmp.GetCurActionMode().PlaySound, .5f, true);

                //TODO: do attack anim
                AnimationTree tree = GetFirstAnimationTree();
                if (tree != null)
                {
                    tree.ActivateTrigger("walkDance");
                }
            }
        }
Пример #4
0
        protected virtual void TickTasks()
        {
            RTSUnit controlledObj = ControlledObject;

            if (controlledObj == null)
            {
                return;
            }

            switch (currentTask.Type)
            {
            //Stop
            case Task.Types.Stop:
                controlledObj.Stop();
                break;

            //Move
            case Task.Types.Move:
            case Task.Types.BreakableMove:
                if (currentTask.Entity != null)
                {
                    controlledObj.Move(currentTask.Entity.Position);
                }
                else
                {
                    Vec3 pos = currentTask.Position;

                    if ((controlledObj.Position.ToVec2() - pos.ToVec2()).Length() < 1.5f &&
                        Math.Abs(controlledObj.Position.Z - pos.Z) < 3.0f)
                    {
                        //get to
                        DoNextTask();
                    }
                    else
                    {
                        controlledObj.Move(pos);
                    }
                }
                break;


            //Reload
            case Task.Types.Reload:
                VBWeaponItem wpn = (controlledObj as VBCharacter).ActiveHeldItem as VBWeaponItem;
                if (wpn != null)
                {
                    wpn.TryReload();
                    DoNextTask();
                }
                break;

            //Pickup
            case Task.Types.PickUp:
                if (InTaskRange())
                {
                    if (currentTask.Entity as VBItem != null)
                    {
                        (controlledObj as VBCharacter).TakeItem(currentTask.Entity as VBItem);
                    }
                    DoNextTask();
                }
                break;

            //Use
            case Task.Types.Use:
                if (InTaskRange())
                {
                    InteractableObject itm = currentTask.Entity as InteractableObject;
                    if (itm != null)
                    {
                        itm.Interact(controlledObj);
                    }
                    DoNextTask();
                }
                break;

            //Talk
            case Task.Types.Talk:
                if (InTaskRange())
                {
                    EngineConsole.Instance.ExecuteString("createWindow chat");
                    DoNextTask();
                }
                break;

            //preuse
            case Task.Types.PreUse:
                break;

            //Attack, Repair
            case Task.Types.Attack:
            case Task.Types.BreakableAttack:
                //case Task.Types.Repair:
                //case Task.Types.BreakableRepair:
            {
                /*/healed
                 * if( ( currentTask.Type == Task.Types.Repair ||
                 *      currentTask.Type == Task.Types.BreakableRepair )
                 *      && currentTask.Entity != null )
                 * {
                 *      if( currentTask.Entity.Health == currentTask.Entity.Type.HealthMax )
                 *      {
                 *              DoNextTask();
                 *              break;
                 *      }
                 * }*/

                float needDistance = controlledObj.Type.OptimalAttackDistanceRange.Maximum;

                MultipleActionItem itm = (controlledObj as VBCharacter).ActiveHeldItem as MultipleActionItem;
                if (itm != null)
                {
                    needDistance = itm.GetCurActionMode().UseDistanceRange.Maximum;
                }

                Vec3 targetPos;
                if (currentTask.Entity != null)
                {
                    targetPos = currentTask.Entity.Position;
                }
                else
                {
                    targetPos = currentTask.Position;
                }

                float distance = (controlledObj.Position - targetPos).Length();

                if (distance != 0)
                {
                    bool lineVisibility = false;
                    {
                        if (distance < needDistance)
                        {
                            lineVisibility = true;

                            //direct line visibility check

                            Vec3 start = ControlledObject.Position;
                            Ray  ray   = new Ray(start, targetPos - start);

                            RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(
                                ray, (int)ContactGroup.CastOnlyContact);

                            foreach (RayCastResult result in piercingResult)
                            {
                                MapObject obj = MapSystemWorld.GetMapObjectByBody(result.Shape.Body);

                                if (obj != null && obj == currentTask.Entity)
                                {
                                    break;
                                }

                                if (obj != controlledObj)
                                {
                                    lineVisibility = false;
                                    break;
                                }
                            }
                        }
                    }

                    //movement control
                    if (lineVisibility)
                    {
                        //stop
                        controlledObj.Stop();

                        RTSCharacter character = controlledObj as RTSCharacter;
                        if (character != null)
                        {
                            character.SetLookDirection(targetPos);
                        }
                    }
                    else
                    {
                        //move to target
                        controlledObj.Move(targetPos);
                    }

                    //weapons control
                    if (lineVisibility)
                    {
                        (ControlledObject as VBCharacter).BaseAttack(currentTask.Entity, null);
                        DoNextTask();

                        /*
                         *                          foreach( Weapon weapon in initialWeapons )
                         *                          {
                         *                                  Vec3 pos = targetPos;
                         *                                  Gun gun = weapon as Gun;
                         *                                  if( gun != null && currentTask.Entity != null )
                         *                                          gun.GetAdvanceAttackTargetPosition( false, currentTask.Entity, false, out pos );
                         *                                  weapon.SetForceFireRotationLookTo( pos );
                         *
                         *                                  if( weapon.Ready )
                         *                                  {
                         *                                          Range range;
                         *
                         *                                          range = weapon.Type.WeaponNormalMode.UseDistanceRange;
                         *                                          if( distance >= range.Minimum && distance <= range.Maximum )
                         *                                                  weapon.TryFire( false );
                         *
                         *                                          range = weapon.Type.WeaponAlternativeMode.UseDistanceRange;
                         *                                          if( distance >= range.Minimum && distance <= range.Maximum )
                         *                                                  weapon.TryFire( true );
                         *                                  }
                         *                          }*/
                    }
                }
            }
            break;
            }
        }