コード例 #1
0
ファイル: AttackTargetBehavior.cs プロジェクト: wshanshan/DDD
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            if (m_done)
            {
                return;
            }
            SimObject me = dmView.AllObjects[m_thisID];
            LocationValue myLocation = me.Location;
            SimObject track = dmView.AllObjects[m_targetID];
            LocationValue trackLocation = track.Location;

            if (!m_attackInProcess) // start the attack
            {
                // start with weapons
                if (me.DockedWeapons.Count > 0)
                {
                    m_attackWeaponID = me.DockedWeapons[0];
                    serverConnection.SendWeaponLaunchRequest(m_thisID, m_attackWeaponID, m_targetID);
                    m_attackEndTime = dmView.SimTime + 12000; // give a two minute time window to start, AttackUpdate will modify this
                    m_attackInProcess = true;
                    m_attackIsWeapon = true;

                }
                else // use native capabilities
                {
                    // figure out capability/vulnerability match up
                    String cap = DetermineCapability(me.CapabilityList, track.VulnerabilityList);
                    if (cap != String.Empty)
                    {
                        serverConnection.SendAttackObjectRequest(m_thisID, m_targetID, cap);
                        m_attackInProcess = true;
                        m_attackIsWeapon = false;
                        m_attackEndTime = dmView.SimTime + 12000;
                    }
                    else //  I don't have the right capabilities, finish up
                    {
                        ResetAttack();
                        m_done = true;
                    }
                }
            }
            else // check to see if the attack was succesful
            {
                // if we are still in attack mode 2 seconds after attack was supposed to end
                // start another attack
                if (dmView.SimTime > m_attackEndTime + 2000)
                {
                    ResetAttack();
                }
            }   
            
        }
コード例 #2
0
ファイル: EngageTargetBehavior.cs プロジェクト: wshanshan/DDD
        public void Update(DDDServerConnection serverConnection, DMView dmView)
        {
            if (m_done)
            {
                return;
            }
            SimObject me = dmView.AllObjects[m_thisID];
            LocationValue myLocation = me.Location;
            SimObject track = dmView.AllObjects[m_targetID];
            LocationValue trackLocation = track.Location;
            m_absoluteLoiterPattern = m_relativeLoiterPattern.ToAbsolute(trackLocation);


            switch (m_engagementState)
            {
                case EngagementState.Tracking:
                    if (ShouldTrack(serverConnection, dmView))
                    {
                        serverConnection.SendMoveObjectRequest(m_thisID, trackLocation, 1);
                    }
                    else
                    {
                        m_engagementState = EngagementState.Attacking;
                        StartLoiter(serverConnection, dmView);
                    }
                    break;
                case EngagementState.Attacking:
                    ContinueLoiter(serverConnection, dmView);
                    if (!m_attackInProcess) // start the attack
                    {
                        // start with weapons
                        if (me.DockedWeapons.Count > 0)
                        {
                            m_attackWeaponID = me.DockedWeapons[0];
                            serverConnection.SendWeaponLaunchRequest(m_thisID, m_attackWeaponID, m_targetID);
                            m_attackEndTime = dmView.SimTime + 12000; // give a two minute time window to start, AttackUpdate will modify this
                            m_attackInProcess = true;
                            m_attackIsWeapon = true;

                        }
                        else // use native capabilities
                        {
                            // figure out capability/vulnerability match up
                            String cap = DetermineCapability(me.CapabilityList, track.VulnerabilityList);
                            if (cap != String.Empty)
                            {
                                serverConnection.SendAttackObjectRequest(m_thisID, m_targetID, cap);
                                m_attackInProcess = true;
                                m_attackIsWeapon = false;
                                m_attackEndTime = dmView.SimTime + 12000;
                            }
                            else //  I don't have the right capabilities, finish up
                            {
                                ResetAttack();
                                if (m_returnAfter)
                                {
                                    m_engagementState = EngagementState.Returning;
                                    m_dddServer.SendMoveObjectRequest(m_thisID, m_originalLocation, 1);
                                }
                                else
                                {
                                    m_done = true;
                                }
                            }
                        }
                    }
                    else // check to see if the attack was succesful
                    {
                        // if we are still in attack mode 2 seconds after attack was supposed to end
                        // start another attack
                        if (dmView.SimTime > m_attackEndTime + 2000)
                        {
                            ResetAttack();
                        }
                    }
                    break;
                case EngagementState.Returning:
                    if (BehaviorHelper.Distance(myLocation, m_originalLocation) < 1)
                    {
                        m_done = true;
                    }
                    break;
            }
        }