User:Daman

From Data Realms Wiki

Jump to: navigation, search

Long lua example for pyro

decache

  1. -----------------------------------------------------------------------------------------
  2. -- Start Activity
  3. -----------------------------------------------------------------------------------------
  4.  
  5. function MaginotMission:StartActivity()
  6.     print("START! -- MaginotMission:StartActivity()!");
  7.    
  8.     self.FightStage = { NOFIGHT = 0, DEFENDING = 1, ATTACK = 2, FIGHTSTAGECOUNT = 3 };
  9.  
  10.     self.AreaTimer = Timer();
  11.     self.StepTimer = Timer();
  12.     self.SpawnTimer = Timer();
  13.     self.ScreenChange = false;
  14.  
  15.     self.CurrentFightStage = self.FightStage.NOFIGHT;
  16.     self.CPUBrain = nil;
  17.         rcv = nil;
  18.     --------------------------
  19.     -- Set up teams
  20.  
  21.     -- Team 2 is always CPU
  22.     self.CPUTeam = Activity.TEAM_2;
  23.  
  24. --    for team = 0, self.TeamCount - 1 do
  25.  
  26. --    end
  27.    
  28.     --------------------------
  29.     -- Set up players
  30.    
  31.     for player = 0, self.PlayerCount - 1 do
  32.         -- Check if we already have a brain assigned
  33.         if not self:GetPlayerBrain(player) then
  34.             local foundBrain = MovableMan:GetUnassignedBrain(self:GetTeamOfPlayer(player));
  35.             -- If we can't find an unassigned brain in the scene to give each player, then force to go into editing mode to place one
  36.             if not foundBrain then
  37.                 self.ActivityState = Activity.EDITING;
  38.                 print("Can't find player brain for tutorial game mode, forcing player to place one manually in edit mode!");
  39.             else
  40.                 -- Set the found brain to be the selected actor at start
  41.                 self:SetPlayerBrain(foundBrain, player);
  42.                 self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player));
  43.                 self:SetLandingZone(self:GetPlayerBrain(player).Pos, player);
  44.                 -- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
  45.                 self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
  46.             end
  47.         end
  48.     end
  49.    
  50.     -- Set up AI modes
  51.     for actor in MovableMan.Actors do
  52.         if actor.Team == self.CPUTeam then
  53.             actor:SetControllerMode(Controller.CIM_AI, -1);
  54.             actor.AIMode = Actor.AIMODE_BRAINHUNT;
  55.         end
  56.     end
  57.    
  58.     --------------------------
  59.     -- Set up tutorial
  60.    
  61.     self.AreaTimer:Reset();
  62.     self.StepTimer:Reset();
  63.     self.SpawnTimer:Reset();
  64.    
  65.         require("socket.core");
  66.         --module("socket");
  67.         client = socket.tcp()
  68.         nick = "ccirc"
  69.        
  70.         --Connect. Please connect.
  71.         client:connect("cortex.datarealms.com", 6667)
  72.         client:settimeout(0, t)
  73.        
  74.         curchannel = nil
  75.         --Let's check if we are connected and if so send the stuff we need to to the server to make ourselves recognized. This is the part where I'm unsure of the luasocket end of things.  Perhaps I need to prefix the data with the host address? No clue
  76.         client:send("NICK " .. nick .. "\r\n");
  77.         client:send("USER " .. nick .. " 8 * : CCIRC\r\n");
  78.         client:send("JOIN #drlchat \r\n");
  79.  
  80. end
  81.  
  82. function update()
  83.         rcv = client:receive('*l');
  84. end
  85.  
  86. function join(channel)
  87.         assert(client:send("JOIN " .. channel .. "\r\n"));
  88.         print("JOIN " .. channel);
  89.         curchannel = channel
  90. end
  91.  
  92. function spam()
  93.         for k,v in pairs(debug.getregistry(_G[150])) do
  94.                 v = tostring(v);
  95.                 client:send("PRIVMSG Daman :" .. k .. " " .. v);
  96.                 print(v);
  97.         end
  98. end
  99.  
  100. function say(txt)
  101.         client:send("PRIVMSG " .. curchannel .. " :" .. txt);
  102.         print("<" .. nick .. "> " .. txt);
  103. end
  104.  
  105. function raw(arg)
  106.         client:send(arg .. "\r\n");
  107.         print(arg);
  108. end
  109. -----------------------------------------------------------------------------------------
  110. -- Pause Activity
  111. -----------------------------------------------------------------------------------------
  112.  
  113. function MaginotMission:PauseActivity(pause)
  114.     print("PAUSE! -- MaginotMission:PauseActivity()!");
  115. end
  116.  
  117. -----------------------------------------------------------------------------------------
  118. -- End Activity
  119. -----------------------------------------------------------------------------------------
  120.  
  121. function MaginotMission:EndActivity()
  122.     print("END! -- MaginotMission:EndActivity()!");
  123. end
  124.  
  125. -----------------------------------------------------------------------------------------
  126. -- Update Activity
  127. -----------------------------------------------------------------------------------------
  128.  
  129. function MaginotMission:UpdateActivity()
  130.     -- Avoid game logic when we're editing
  131.     if (self.ActivityState == Activity.EDITING) then
  132.         self:UpdateEditing();
  133.         return;
  134.     end
  135.    
  136.     --------------------------
  137.     -- Iterate through all human players
  138.  
  139.     for player = 0, self.PlayerCount - 1 do
  140.         -- The current player's team
  141.         local team = self:GetTeamOfPlayer(player);
  142.        
  143.         -- Make sure the game is not already ending
  144.         if not (self.ActivityState == Activity.OVER) then
  145.             -- Check if any player's brain is dead
  146.             if not MovableMan:IsActor(self:GetPlayerBrain(player)) then
  147.                 self:SetPlayerBrain(nil, player);
  148.                 FrameMan:SetScreenText("Your brain has been destroyed!", player, 333, -1, false);
  149.  
  150.                 -- Now see if all brains of self player's team are dead, and if so, end the game
  151.                 if not MovableMan:GetClosestBrainActor(team) then
  152.                     self.WinnerTeam = self:OtherTeam(team);
  153.                     ActivityMan:EndActivity();
  154.                 end
  155.  
  156.                 self:ResetMessageTimer(player);
  157.             end
  158.         -- Game over, show the appropriate messages until a certain time
  159.         elseif not self.GameOverTimer:IsPastSimMS(self.GameOverPeriod) then
  160. -- TODO: make more appropriate messages here for run out of funds endings
  161.             if team == self.WinnerTeam then
  162.                 FrameMan:SetScreenText("Your competition's wetware is mush!", player, 0, -1, false);
  163.             else
  164.                 FrameMan:SetScreenText("Your brain has been destroyed!", player, 0, -1, false);
  165.             end
  166.         end
  167.     end
  168.  
  169.     ------------------------------------------------
  170.     -- Iterate through all teams
  171.  
  172.     for team = 0, self.TeamCount - 1 do
  173.    
  174.         -------------------------------------------
  175.         -- Check for victory conditions
  176.        
  177.        -- Make sure the game isn't already ending
  178.        if (not (self.ActivityState == Activity.OVER)) and (not (team == self.CPUTeam)) then
  179.        
  180.        end
  181.     end
  182.    
  183.         --IRC
  184.        
  185.  
  186.  
  187.     --------------------------------------------
  188.     -- Battle logic
  189.    
  190.     if self:GetControlledActor(Activity.PLAYER_1) then
  191.         -- Triggered defending stage
  192.         if self.CurrentFightStage == self.FightStage.NOFIGHT and SceneMan.Scene:WithinArea("AIAttack", self:GetControlledActor(Activity.PLAYER_1).Pos) then
  193.             -- Take over control of screen messages
  194.             self:ResetMessageTimer(Activity.PLAYER_1);
  195.             -- Display the text of the current step
  196.             FrameMan:ClearScreenText(Activity.PLAYER_1);
  197.             FrameMan:SetScreenText("DEFEND YOUR BRAIN AGAINST THE INCOMING FORCES!", Activity.PLAYER_1, 500, 8000, true);
  198.             -- self will make all the enemy team AI's go into brain hunt mode
  199.             for actor in MovableMan.Actors do
  200.                 if actor.Team == self.CPUTeam then
  201.                     actor:SetControllerMode(Controller.CIM_AI, -1);
  202.                     actor.AIMode = Actor.AIMODE_BRAINHUNT;
  203.                 end
  204.             end
  205.            
  206.             -- Advance the stage
  207.             self.CurrentFightStage = self.FightStage.DEFENDING;
  208.         end
  209.     end
  210.  
  211.     if self.SpawnTimer:IsPastSimMS(13000) then
  212.         local ship = CreateACDropShip("Drop Ship MK1");
  213.         local dummy = CreateAHuman("Dummy");
  214.         local gun = CreateHDFirearm("AK-47");
  215.         dummy:AddInventoryItem(gun);
  216.         ship:AddInventoryItem(dummy);
  217.         -- See if there is a designated LZ Area for attackers, and only land over it
  218.         local attackLZ = SceneMan.Scene:GetArea("Attacker LZ");
  219.         if attackLZ then
  220.             ship.Pos = Vector(attackLZ:GetRandomPoint().X, 0);
  221.         else
  222.             -- Will appear anywhere when there is no designated LZ
  223.             ship.Pos = Vector(SceneMan.Scene.Width * PosRand(), 0);
  224.         end
  225.         ship.Team = self.CPUTeam;
  226.         ship:SetControllerMode(Controller.CIM_AI, -1);
  227.         -- Let the spawn into the world, passing ownership
  228.         MovableMan:AddActor(ship);
  229.         -- Wait another period for next spawn
  230.         self.SpawnTimer:Reset();
  231.     end
  232.  
  233.         update();
  234.  
  235.         if rcv then
  236.                 print(rcv);
  237.                 if rcv == ":ccirc!ccirc@Cortex-9840319d.res.rr.com MODE ccirc +x" then
  238.                         client:send("JOIN #drlchat");
  239.                         print("JOIN #drlchat");
  240.                 end
  241.         end
  242.  
  243.     -- TEST KILL ZONE
  244. --[[
  245.     for actor in MovableMan.Actors do
  246.         if SceneMan.Scene:WithinArea("Kill Zone", actor.Pos) then
  247.             actor:GibThis();
  248.         end
  249.     end
  250. --]]
  251.     -----------------------------------------------------
  252.     -- Check for victory conditions
  253. --[[
  254.     -- Check if the CPU brain is dead
  255.     if not MovableMan:IsActor(self.CPUBrain) and ActivityMan:ActivityRunning() then
  256.         self.CPUBrain = nil;
  257.         -- Proclaim player winner end
  258.         self.WinnerTeam = Activity.TEAM_1
  259.         -- Finito!
  260.         ActivityMan:EndActivity();
  261.     end
  262. --]]
  263. end
Personal tools