Page 3 of 4

Re: AI Switcher

Posted: Wed May 08, 2013 2:37 am
by Komag
but it's not what they drop, it's what drops when it hits the monster, which happens when you mouse-toss something

Re: AI Switcher

Posted: Wed May 08, 2013 2:23 pm
by Damonya
Komag wrote:You can take a look at my snail king fight code (in snailWallScript on level 7) which solves this by counting all projectiles (they don't all count the same way either) and spawning the ones that are stuck "inside" the monster on the floor at the time of "teleport" or destroying the monster. I used onDie and onProjectileHit hooks. Part of the code has to account for possible "mouse thrown" projectiles which don't stick but do register as projectile hits.
This ?

snailWallScript:

Code: Select all

function snailDie() 
_restoreProj()
end


function projHit(proj) -- trig by snail_king onProjectileHit hook
  pr.nt("snail king hit by "..proj.name)
  local p = {"cold_arrow",  "fire_arrow",  "poison_arrow",  "shock_arrow",  "arrow"}
  local q = {"cold_quarrel","fire_quarrel","poison_quarrel","shock_quarrel","quarrel"}
  local r = {"throwing_knife","shuriken","throwing_axe"}
  for i=1,5 do
    if proj.name == p[i] then snailArrows = snailArrows + 1 end
    if proj.name == q[i] then snailQurrls = snailQurrls + 1 end
  end
  if proj.name == r[1] then snailKnives = snailKnives +1 end
  if proj.name == r[2] then snailShrkns = snailShrkns +1 end
  if proj.name == r[3] then snailAxes   = snailAxes   +1 end
end

snailArrows = 0
snailQurrls = 0
snailKnives = 0
snailShrkns = 0
snailAxes   = 0

function _restoreProj() -- trig by snailDie()
  local cArws = 0
  local cQrls = 0
  local cKnvs = 0
  local cShks = 0
  local cAxes = 0
  for i in entitiesAt(7,10,31) do
    if       i.name == "arrow"          then cArws = cArws + 1
      elseif i.name == "quarrel"        then cQrls = cQrls + 1
      elseif i.name == "throwing_knife" then cKnvs = cKnvs + 1
      elseif i.name == "shuriken"       then cShks = cShks + 1
      elseif i.name == "throwing_axe"   then cAxes = cAxes + 1
    end
  end
  local a = snailArrows - cArws
  local b = snailQurrls - cQrls
  local c = snailKnives - cKnvs
  local d = snailShrkns - cShks
  local e = snailAxes   - cAxes
  local t1 = {"arrow","quarrel","throwing_knife","shuriken","throwing_axe"}
  local t2 = {a,b,c,d,e}
  for h=1,5 do
    if t2[h] > 0 then for i = 1,t2[h] do
       local c=math.random(1,2) local d=1 if c==1 then d=-1 end
       local e=math.random(1,2) local f=1 if e==1 then f=-1 end
       local g=math.random(1,2) local z=1 if g==1 then z= 3 end
       spawn(t1[h],7,10,31,z)
        :setSubtileOffset(math.random()*d,math.random()*f)
    end end
  end
end
monsters.lua

Code: Select all

	onDie = function(self)
	   snailWallScript.snailDie()
	   return false
	end,
	onProjectileHit = function(self,proj,amt,type)
	   snailWallScript.projHit(proj)
	end,
Indeed it would be interesting to implement it in AI switcher

Re: AI Switcher

Posted: Wed May 08, 2013 2:36 pm
by Xanathar
Yes, it's not that easy however, for two reasons:

1) the AI switcher can be used on whatever dungeons and has no knowledge of what the throwing weapons in that dungeon are - it needs to tell between fragile projectiles, sharp projectiles and the others since only non-fragile sharp projectiles should be preserved. This adds a burden of configuration to be done by who uses AI switcher (though I fear there is no way out of this, unless I'm missing something).

2) the monsters to be managed are a ton and in different forms - so this means having to keep a per-instance context of every-monster which is something that can be useful anyway but I was keen to avoid for simplicity.. but I guess I can't procrastinate it any longer :D

Will try to get the hands dirty on it soon and see what I can do regarding this. :|

Re: AI Switcher

Posted: Wed May 08, 2013 8:46 pm
by JKos
I got some hacky idea, but don't know if it really works: Instead of destroying the monster when the AI switch happens, just move the monster in to a some wall-tile (with monster:setPosition), and when the active monster dies kill the one in wall tile too (with damageTile), and move dropped items to the location of the active monster (by destroying and recreating them, should be easy with grimq).

Re: AI Switcher

Posted: Wed May 08, 2013 8:48 pm
by Komag
sounds like it would work :)

Re: AI Switcher

Posted: Wed May 08, 2013 9:07 pm
by Diarmuid
Not sure if moving a monster in a wall works...

Re: AI Switcher

Posted: Wed May 08, 2013 9:30 pm
by JKos
I tested it and moving monster in a wall works (and killing it when it's in a wall), but the tile must be surrounded with another wall tiles, otherwise the monster can escape from it. I didn't test it in game, only in editor.

Re: AI Switcher

Posted: Thu May 09, 2013 9:43 pm
by Xanathar
Good idea.. the only problem I foresee with that is the loot, which would get potentially duplicated many times, but I can work around that by taking care myself of the loot process in place of the game engine.

Will test and report! Thanks! :)

Re: AI Switcher

Posted: Fri May 10, 2013 11:36 pm
by Xanathar
I'm trying both solutions.

Solution 1 - keeping a list of all the projectiles hitting a monster and respawning them later.

This seem to work but is cheatable. For example take a shuriken, throw (not shoot!) to the monster, now the shuriken is duplicated (as if thrown with the mouse and not by an attack, it still counts as a projectile but does not stuck in the monster).

Solution 2 (monster moved to walls) is giving me even more problems, but will try again tomorrow (at the very least, there is the problem of not counting projectiles shoot by the monster itself when inside the wall, plus not being able to preserve the monster id as killing does not remove the id immediately - there are severe timing issues with this method).

Re: AI Switcher

Posted: Sat May 11, 2013 2:58 am
by Komag
Xanathar wrote:...This seem to work but is cheatable. For example take a shuriken, throw (not shoot!) to the monster, now the shuriken is duplicated (as if thrown with the mouse and not by an attack, it still counts as a projectile but does not stuck in the monster).
That's why I have the script count any on the ground first and subtract that from the total. If the monster can move around a lot it's harder, but the ground could be searched a moment after every projectile hit registers, to see if a new item is found, indicated the player threw it instead of shooting it, and not add it to the total.